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 Mon, Dec 31, 2007 at 02:43:44PM -0800, gst wrote:
> hi,
>
> iirc, in C if I store somwhere a pointer to a "stack" value (e.g.:
> call a function with an auto variable, return its pointer) i know i'm
> going to mess things, since that piece of data will be most probably
> overwritten by subsequ
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
>
From: gst <[EMAIL PROTECTED]>
> iirc, in C if I store somwhere a pointer to a "stack" value (e.g.:
> call a function with an auto variable, return its pointer) i know i'm
> going to mess things, since that piece of data will be most probably
> overwritten by subsequent calls.
>
> if I do the same
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
On Jan 1, 2008 2:32 PM, Chas. Owens <[EMAIL PROTECTED]> wrote:
snip
> You can deal with this by using the anonymous arrayref generator:
snip
Oh, the proper term is "anonymous array composer" (at least according
to the 3rd Camel). I knew "anonymous arrayref generator" sounded
wrong.
--
To unsubs
On Mon, 31 Dec 2007 14:43:44 -0800, gst wrote:
> iirc, in C if I store somwhere a pointer to a "stack" value (e.g.:
> call a function with an auto variable, return its pointer) i know i'm
> going to mess things, since that piece of data will be most probably
> overwritten by subsequent calls.
>
>
On Jan 1, 2008 2:12 PM, Chas. Owens <[EMAIL PROTECTED]> wrote:
snip
> > if I do the same in Perl (with a hard ref), do I have any guarantee
> > that the same behavior (implicit aliasing) does - or does not (every
> > new scalar is guaranteed to not alias the old non existant value) -
> > apply?
sni
On Dec 31, 2007 5:43 PM, gst <[EMAIL PROTECTED]> wrote:
> hi,
>
> iirc, in C if I store somwhere a pointer to a "stack" value (e.g.:
> call a function with an auto variable, return its pointer) i know i'm
> going to mess things, since that piece of data will be most probably
> overwritten by subseq
IIRC, the stack pointer is part of the operating system, not the C language.
When a subroutine is called, the parameters are pushed to the stack,
and the return value is stored in a specific register.
When a routine creates a variable, the system's memory allocator finds
a new piece of unused memor
On Dec 31, 2007 2:43 PM, gst <[EMAIL PROTECTED]> wrote:
> iirc, in C if I store somwhere a pointer to a "stack" value (e.g.:
> call a function with an auto variable, return its pointer) i know i'm
> going to mess things, since that piece of data will be most probably
> overwritten by subsequent ca
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,
iirc, in C if I store somwhere a pointer to a "stack" value (e.g.:
call a function with an auto variable, return its pointer) i know i'm
going to mess things, since that piece of data will be most probably
overwritten by subsequent calls.
if I do the same in Perl (with a hard ref), do I have
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
Nash wrote:
Hi all,
I'm new to Perl and I'm trying to use it to connect to a shared disc
through a home network. This is what I've tried:
#!/usr/bin/perl -w
use Win32::NetResource;
19 matches
Mail list logo