ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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
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.
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
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.