John W. Krahn [JWK], on Tuesday, March 08, 2005 at 12:58 (-0800) made
these points:
JWK> my $string = 'something/other/foo/bar';
JWK> my $count;
JWK> my $kw = { map { 'cat' . ++$count, $_ } split /\//, $string };
this is really tricky reply I awaited, I like this solution, really
nice. Also, in m
Ing. Branislav Gerzo wrote:
Hello beginners@perl.org,
Hello,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw->{cnt}++;
$kw->{cat${kw->{cnt}}} = $cat }
I get: Can't use bareword ("kw") as a HASH ref while "s
> Hello beginners@perl.org,
>
>
> I get: Can't use bareword ("kw") as a HASH ref while "strict refs" in
> use..
> The goal is to get something like:
> $kw->{cat1} = 'something',
> $kw->{cat2} = 'other',
> $kw->{cat3} = 'foo',
> $kw->{cat4} = 'bar'
>
Well, fixing the typo where you build the key
Ing. Branislav Gerzo wrote:
Hello beginners@perl.org,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw->{cnt}++;
$kw->{cat${kw->{cnt}}} = $cat }
Change this line to
for my $cat (split(/\//, 'something/oth
Ing. Branislav Gerzo wrote:
Hello beginners@perl.org,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw->{cnt}++;
$kw->{cat${kw->{cnt}}} = $cat }
You don't have to accept the rope Perl will give you to hang y
Sent: Tuesday, March 08, 2005 10:14 PM
To: beginners@perl.org
Subject: tricky hash
Hello beginners@perl.org,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw->{cnt}++;
$kw->{cat${kw->{c
Hello beginners@perl.org,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw->{cnt}++;
$kw->{cat${kw->{cnt}}} = $cat }
I get: Can't use bareword ("kw") as a HASH ref while "strict refs" in
use..
The goal i