[prog] perl string question
mc
mcgonzalez at att.net
Thu Feb 27 18:56:30 EST 2003
On Thu, 2003-02-27 at 17:41, Jacinta Richardson wrote:
> You can use split:
>
> my ($part1, $part2, $part3, $messageid) = split ':', $line;
> $part1 = join '', $part1, $part2, $part3;
>
> or
>
> my @bits = split ':', $line;
> my $messageid = pop @bits;
> my $part1 = join '', @bits;
>
> or
>
> my ($part1, $messageid) = ($line =~ m/^(.+):(Message.+)$/);
How cool! Split it then join the first bits together! I have to admit,
my addled brain did not even think of that.
>
>
> As to how to print to a file.
>
> open FILE, "< $file" or die "Failed to open $file for reading: $!";
> print FILE "$part1\n$messageid\n";
> close FILE;
I figured it was close to this, I had it as 2 separate prints rather
than just 1. The 1 is much nicer.
>
> Good luck with it.
>
> Jacinta
Thank you thank you thank you! I think you knocked some sense into my
brain :)
--
mc
I haven't lost my mind,
It is backed up on disk somewhere.
4M
More information about the Programming
mailing list