Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

cmd o/p- each line should be stored as each element in an Array?

by G Nagasri Varma (Novice)
on Dec 02, 2015 at 20:04 UTC ( [id://1149211]=perlquestion: print w/replies, xml ) Need Help??

G Nagasri Varma has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.
  • Comment on cmd o/p- each line should be stored as each element in an Array?

Replies are listed 'Best First'.
Re: cmd o/p- each line should be stored as each element in an Array?
by Discipulus (Canon) on Dec 02, 2015 at 20:14 UTC
    reading perlintro in less than one hour can be the first step, a fistfull of minutes reading about lists and few seconds for a bunch of basic functions like split.
    Add some <c> ..</c> (code tags) and serve hot with red wine.

    L*
    PS more effort, best answer.
    PPS what o/p means?
    There are no rules, there are no thumbs..
    Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: cmd o/p- each line should be stored as each element in an Array?
by stevieb (Canon) on Dec 02, 2015 at 20:09 UTC

    Welcome to the Monastery, G Nagasri Varma!

    Please show us the code you've tried. Without that, it's impossible to tell what's going wrong.

Re: cmd o/p- each line should be stored as each element in an Array?
by NetWallah (Canon) on Dec 02, 2015 at 22:20 UTC
    How can this be acheived?
    It can be achieved thus:
    perl -ne 'chomp; push @x,$_' Your_file_name
    or, more traditionally:
    chomp ( my @x = <> );
    What have you tried ?

            Our business is run on trust. We trust you will pay in advance.

      chomp ( my @x = <> );
      The above one worked, but array is getting all the entire list of values. But in the index zero, why isnt first value being stored.
      o/p:
      1431037440 1431038327
      $files[0]=
      $files1=1431037440

        Is there an empty line at the beginning of your input file?

        If that's not the case, you should try to create an →SSCCE
        To filter out empty lines (or lines not containing digits), try:
        chomp ( my @x = grep{/\d/} <> );

                Our business is run on trust. We trust you will pay in advance.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (4)
As of 2024-04-24 22:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found