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

Re: array problem

by katgirl (Hermit)
on Sep 12, 2003 at 12:55 UTC ( [id://291013]=note: print w/replies, xml ) Need Help??


in reply to array problem

@a = ABC isn't an array. Do you mean @a = ("A","B","C");? If so...

#!/agl/tools/perl/bin/perl my @a=qx (rsh -l sonaxisz 'source.login ; findbug -p | sort -u | %s se +rver); print "Content-type:text/html\n\n"; print "<html><body><table>"; for(@a){ print "<tr><td>$_</td></tr>"; } print "</table></body></html>";
the for loop takes each item in the list @a and applies the code within the loop - but you could use map instead:
@a = ("A","B","C"); print "Content-type:text/html\n\n"; print "<html><body><table>"; print map("<tr><td>$_</td></tr>",@a); print "</table></body></html>";
any good for you?

Replies are listed 'Best First'.
Re: Re: array problem
by bory (Beadle) on Sep 12, 2003 at 13:06 UTC
    It is a very good ideea but i am not sure if qx returns separate items for output! I relly don't think so! Do you know any quotelike operators that returns separate items for output! Thank you for your time!!

        Wait...qx will return a list of command output lines...if your pipeline outputs newline separated lines, then you'll get a list of the kind that you seem to want.

        Compare this code and its outputs with what you have done.

        my @a = map {s/\n//g ? $_ : ()} `netstat -an`; print "$_\n" for @a;

    Log In?
    Username:
    Password:

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

    How do I use this?Last hourOther CB clients
    Other Users?
    Others meditating upon the Monastery: (5)
    As of 2024-04-23 14:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found