LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-26-2003, 07:24 PM   #1
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
dereferencing anonymous arrays in Perl


Hey guys,

In Perl you can create anonymous arrays, i'm having trouble understanding something:

Code:
@array= (1,2,3);
$ref= \@array; # create reference
print @$ref; # standard dereference

# can create a reference to an anonymous array as follows:

$ref= [@array]; 
print @$ref; # dereference

# So why then won't this work:

print @[@array]; # why won't this work?

# Why do you have to do this instead?

print @{[@array]};
Can someone explain why @{} is required?

Thanks in advance...

cools

Last edited by coolman0stress; 10-26-2003 at 09:04 PM.
 
Old 10-26-2003, 08:54 PM   #2
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
well i know the simple explanation is b/c of operator precedence. you want to apply the
'@' operator to the entire expression [@array]. using { } creates a separate block of code
for that to run in. then the expression is dereferenced.
 
Old 10-26-2003, 09:08 PM   #3
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Original Poster
Rep: Reputation: 30
Humm.. that does make sense, so why then can't you seperate the @ from the rest using ():

print @([@array]);

Or do the paranthesis prevent returning of anonymous array reference to use with @?

Last edited by coolman0stress; 10-26-2003 at 09:29 PM.
 
Old 10-27-2003, 12:24 AM   #4
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
honestly i dont know. im no perl wizard. the book i was looking thru sux, it didn't explain it. i just remember that was always the syntax used, and i remember finding it hard to understand as well. i dont really program in perl much, i'd be scared to show anyone my perl scripts as they are prolly hideous! C for me, sorry i can't help u anymore, maybe some perl monkeys can
 
Old 10-27-2003, 05:36 PM   #5
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Original Poster
Rep: Reputation: 30
Well thanks for your help so far.

I'm revisiting Perl in general. I took a course last semester and though i was very excited at first, in the end i was some what dissappointed. So now i'm digging a bit deeper and see what i can find.
 
Old 10-27-2003, 10:11 PM   #6
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
heh that's quite funny. i learned perl this summer just b/c i wanted to see how other languages are(im a c* guy). at first it was cool with all the shortcuts and whatnot, but then when it came to actually create a serious program...i just laughed. i donno, i dont take perl serious. i just use it to write utilities and page long at most scripts. i didn't really find CGI programming fun at all, it's too visual for my likes. im more into nuts and bolts then pretty colors i guess. but my friends all tell me that im missing out on the good stuff in perl... maybe one day i'll have to buy the o'reilly books and really learn it
 
Old 10-27-2003, 10:17 PM   #7
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Original Poster
Rep: Reputation: 30
I definately share your views on Perl. I got the exact same feelilng at first: "WOW look how fast i can write this and that". Once it came to writing anything longer than 200 lines, damn does it get annoying and dissorganized fast.

After taking a break from it i got offered a "quick" job making a website. So now i'm taking the time to review but also go deeper than before.

So now i'm checking out gui programming with Tk. So far (being Perl), it's fairly easy and straightforward (i'm comparing to the stuff i've done so far in Java swing). We'll see how it turns out once i try to write larger apps.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
perl: concatenate arrays jrtayloriv Programming 2 01-23-2005 07:13 AM
PERL : Arrays confusing? fredgt Programming 3 12-19-2004 08:24 AM
merging arrays suing perl pantera Programming 1 06-03-2004 08:51 AM
arrays in perl BBQ_Matt Programming 3 09-23-2003 07:45 AM
Perl question re arrays/variable names Jon- Linux - Software 1 09-19-2003 10:29 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:32 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration