* Paul Johnson [2008.01.01 22:10]:
> The most direct analogy would be to use an
> in-memory file:
>
> open my $fh, "<", \$scalar;
> print while <$fh>;
Very nice. Thanks.
I didn't understand what John and Chas were trying
to say until I saw the term "in-memory file".
Exactly the kind of stuff I
Chas. Owens wrote:
If you have a recent enough version of Perl* you can say
open my $fh, "<", \$scalar
or die "could not attach a file handle to \$scalar: $!";
while (my $line = <$fh>) {
chomp($line);
#do stuff with $line
}
* 5.8 can do this, but I am not sure about 5.6.*
perldo
On Mon, Dec 31, 2007 at 05:56:35PM -0500, Jean-Rene David wrote:
> I wonder what idioms are available to loop through
> the lines stored in a scalar variable. I guess I'm
> looking for something analogous to these idioms
> for files and arrays respectively:
>
> while() {
> # do stuff
> }
>
> for
On Jan 1, 2008 12:21 PM, yitzle <[EMAIL PROTECTED]> wrote:
> You can skip the array assignment and just do:
>
> foreach ( split "\n", $scalar ) {
> ...
> }
>
> I predict a reply that uses map()... though I think that using a map
> isn't really another solution, but just an alternative to the for
>
Jean-Rene David wrote:
Hi,
Hello,
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while() {
# do stuff
}
open FH, '<', \$scalar or die "Cannot open \$sca
Jean-Rene David wrote:
Hi,
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while() {
# do stuff
}
foreach (@array) {
# do stuff
}
When I had to do this I sp
You can skip the array assignment and just do:
foreach ( split "\n", $scalar ) {
...
}
I predict a reply that uses map()... though I think that using a map
isn't really another solution, but just an alternative to the for
loop.
map {stuff}, split "\n", $scalar;
But I think the answer is basica
On Dec 31, 2007 2:56 PM, Jean-Rene David <[EMAIL PROTECTED]> wrote:
> When I had to do this I split the scalar in an
> array:
>
> @array = split "\n", $scalar;
> foreach (@array) {
> # do stuff
> }
>
> What would be some other ways to do this? (This is
> purely curiosity.)
This type of curiosity
On Dec 31, 2007 5:56 PM, Jean-Rene David <[EMAIL PROTECTED]> wrote:
> Hi,
>
> I wonder what idioms are available to loop through
> the lines stored in a scalar variable. I guess I'm
> looking for something analogous to these idioms
> for files and arrays respectively:
>
> while() {
> # do stuff
> }
Hi,
I wonder what idioms are available to loop through
the lines stored in a scalar variable. I guess I'm
looking for something analogous to these idioms
for files and arrays respectively:
while() {
# do stuff
}
foreach (@array) {
# do stuff
}
When I had to do this I split the scalar in an
arra
10 matches
Mail list logo