Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: what is @$varname in perl

by 2teez (Vicar)
on Jul 03, 2014 at 10:06 UTC ( [id://1092134]=note: print w/replies, xml ) Need Help??


in reply to what is @$varname in perl

Hi sandy105,

..however i do not understand what @$row is.. and YET you had the code above written? That doesn't add up for me.

More so, if you have to deal with CSV files, think of using either Text::CSV_XS or Text::CSV than hand-picking commas using split and others.

If you tell me, I'll forget.
If you show me, I'll remember.
if you involve me, I'll understand.
--- Author unknown to me

Replies are listed 'Best First'.
Re^2: what is @$varname in perl
by redbull2012 (Sexton) on Jul 03, 2014 at 10:12 UTC

    @$row is a short way of saying:

    my @arr = split(/,/, $line ); my $row = \@arr;
    Regards,

      Please could your answer be directed to the OP not me. Thanks

      If you tell me, I'll forget.
      If you show me, I'll remember.
      if you involve me, I'll understand.
      --- Author unknown to me
Re^2: what is @$varname in perl
by sandy105 (Scribe) on Jul 03, 2014 at 10:23 UTC

    "i had to write a csv sorting code for which i used the following code :"

    i wrote this multithreaded program to sort files in parallel ,this was actually the subroutine part (sort of).initial code which i tried would append sorted line to previous line, so 2 lines would be clubbed in 1 line ; hence i found THIS code on net

    initial code below

    foreach(@csvfiles) { $csvfile=$_; open(hanr,"D:\\stock\\".$csvfile) or die"error read $!\n"; open(hanw,">D:\\stock\\sorted".$csvfile) or die"error write $!\n"; @lines = (); @lines = <hanr>; shift(@lines);#remove header csv @sorted = sort multisort @lines; sub multisort { ($field1a, $field2a, $field3a)=split(/\,/, $a); ($field1b, $field2b, $field3b)=split(/\,/, $b); $field1a cmp $field1b or $field2a cmp $field2b; } print hanw @sorted; close(hanw); close(hanr); }

      Well, the above code makes sense. Maybe it is not very efficient because it splits lines inside of the sort, but it should work.

      It looks like you don't know perl, so it is bad idea to write in perl when you don't know it. So either learn it, or ask someone to write the code that you need. For that, specify exactly what the code should do.

      It's just hard to answer random questions about perl, when the listener does not know much about it. Without ground knowledge the answers won't make sense.

        It looks like you don't know perl, so it is bad idea to write in perl when you don't know it. So either learn it, or ask someone to write the code that you need.

        What? You must be kidding. Writing Perl code is certainly and by far the most important step to learn the language. Using tutorials and books is certainly very important, but the only right way to learn a language (whether a spoken language or a programming language) is to practice it.

        Consider what Larry Wall is writing in the final section of the first chapter of the Camel Book (Programming Perl):

        What You Don't Know Won't Hurt You (Much)

        Finally, allow us to return once more to the concept of Perl as a natural language. Speakers of a natural language are allowed to have differing skill levels, to speak different subsets of the language, to learn as they go, and generally, to put the language to good use before they know the whole language. You don't know all of Perl yet, just as you don't know all of English. But that's Officially Okay in Perl culture. You can work with Perl usefully, even though we haven't even told you how to write your own subroutines yet. We've scarcely begun to explain how to view Perl as a system management language, or a rapid prototyping language, or a networking language, or an object-oriented language. We could write entire chapters about some of these things. (Come to think of it, we already did.)

        To the OP: yes, by all means, write Perl code, even if it is what is sometimes called "baby Perl" at first. Most (if not all) of us have started this way, using first a small subset of the language and then gradually expanding the language knowledge.

        i started just 3 days back , but i am not new to programming .just that some perl code seems cryptic .for eg this program required almost 4X lines of code in java.

        however its not my choice i have to learn perl for use in my project, thanks for ur help and guidance

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1092134]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found