vxp has asked for the wisdom of the Perl Monks concerning the following question:
Suppose you have this input:
line1 line2 line3 line4 line5
And the following code:
#!/usr/bin/perl my $file = shift; local( $/, *INPUT ); open(INPUT, $file); $input = <INPUT>; print $input;
Is there a way to transform that $input scalar into an array? I realize that local( $/, *INPUT ); gets rid of the new lines. I also don't have any special separators in my actual input (my "real" input is a lot like this "fake" input, except that its MIME encoded, and I decode it using MIME::QuotedPrint::Perl. Which by the way, is why I'm doing local( $/, *INPUT ); in the first place.. I have to read the whole MIME-encoded file into a scalar to decode it. Can't read it in line by line because of that. :/ )
I just want to iterate through $input line by line and do something with each..so, somehow, I need to turn it into an array :)
Any thoughts/suggestions/solutions welcome!
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Transforming a scalar to an array
by ikegami (Patriarch) on Jul 15, 2009 at 14:59 UTC | |
Re: Transforming a scalar to an array
by davorg (Chancellor) on Jul 15, 2009 at 15:04 UTC | |
by ikegami (Patriarch) on Jul 15, 2009 at 15:19 UTC | |
Re: Transforming a scalar to an array
by Anonymous Monk on Jul 15, 2009 at 15:07 UTC | |
by AnomalousMonk (Archbishop) on Jul 15, 2009 at 16:44 UTC | |
Re: Transforming a scalar to an array
by vxp (Pilgrim) on Jul 15, 2009 at 15:57 UTC |