help about array and hash

S

sonet

undef %saw;

@saw{@in} = (); #why? @saw not $saw, @saw is array or
hash?<===============
@out = sort keys %saw; # remove sort if undesired


undef @ary;
@ary[@in] = @in; #why? @saw not $saw<===============
@out = grep {defined} @ary;
 
P

phaylon

sonet said:
#why? @saw not $saw, @saw is array or hash?<===============

That's absolutely gibberish for me, but my third eye says you should get a
look at hash-slices in perldoc perldata. Also you should read the posting
guidelines, which were last posted awful 10 hours ago.
 
P

Paul Lalli

sonet said:
undef %saw;

@saw{@in} = (); #why? @saw not $saw, @saw is array or
hash?<===============
@out = sort keys %saw; # remove sort if undesired


undef @ary;
@ary[@in] = @in; #why? @saw not $saw<===============
@out = grep {defined} @ary;


@saw{@in} is a hash slice
@ary[@in] is an array slice

You can read more about slices in:
perldoc perldata

Search for the section labeled "Slices"

Hope this helps,
Paul Lalli
 
A

A. Sinan Unur

undef %saw;
WTF?

@saw{@in} = (); #why? @saw not $saw, @saw is array or
hash?<===============
@out = sort keys %saw; # remove sort if undesired

Do you need lumber?
undef @ary;
@ary[@in] = @in; #why? @saw not $saw<===============

I don't mean to be disrespectful here but are you suffering from some
mental problem that cuases you to repeat "@saw not $saw" ad infinitum? I
tried saying that repeatedly and did not do anything for me. What does it
do for you?


Please read the posting guidelines posted here frequently for advice on
how to help others help you. First, make sure to always put

use strict;
use warnings;

in your scripts. With that:

use strict;
use warnings;

undef %saw;

@saw{@in} = ();
@out = sort keys %saw;

undef @ary;
@ary[@in] = @in;
@out = grep {defined} @ary;

__END__

generates the following messages:

C:\Documents and Settings\asu1\My Documents> t.pl
Global symbol "%saw" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 4.
Global symbol "%saw" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 6.
Global symbol "@in" requires explicit package name at C:\Documents and
Settings\
asu1\My Documents\t.pl line 6.
Global symbol "@out" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 7.
Global symbol "%saw" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 7.
Global symbol "@ary" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 10.
Global symbol "@ary" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 11.
Global symbol "@in" requires explicit package name at C:\Documents and
Settings\
asu1\My Documents\t.pl line 11.
Global symbol "@in" requires explicit package name at C:\Documents and
Settings\
asu1\My Documents\t.pl line 11.
Global symbol "@out" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 12.
Global symbol "@ary" requires explicit package name at C:\Documents and
Settings
\asu1\My Documents\t.pl line 12.
Execution of C:\Documents and Settings\asu1\My Documents\t.pl aborted due
to com
pilation errors.

What are you trying to do?

Sinan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top