Loading ...
Sorry, an error occurred while loading the content.
 

Re: Problem in puuting code in single line with foreach

Expand Messages
  • avnit singh
    hi , this is amazing you are messing up my friend see the syntax what will be printented if $_ is a wide space up front so you will get an error try for
    Message 1 of 3 , Jul 6, 2006
      hi ,
      this is amazing you are messing up my friend see the syntax what will
      be printented if $_ is a wide space up front so you will get an error
      try
      for each(@ARGV)
      {print ...}
      is corr
      --- In perl-beginner@yahoogroups.com, Ashish Gupta
      <ashish_gupta_cal@...> wrote:
      >
      > Hi,
      >
      > I am writing a perl program, which accepts arbitrary number of
      integers as input and prints all the even numbers. But I am not
      supposed to use any user-defined variable.
      >
      > So following code works...
      >
      > #! /usr/bin/perl -wl
      > foreach (@ARGV){
      > print unless($_ %2);
      > }
      >
      > But problem is if I try to shrink the code, it doesn't works...
      > #! /usr/bin/perl -wl
      > print unless($_ %2) foreach (@ARGV);
      >
      > I get the error...
      > syntax error at test5.pl line 3, near ") foreach "
      >
      > Can someone please point out what's wrong in the above code.
      >
      > Thanks and Regards,
      > Ashish
      >
      >
      > ---------------------------------
      > Sneak preview the all-new Yahoo.com. It's not radically different.
      Just radically better.
      >
      > [Non-text portions of this message have been removed]
      >
    Your message has been successfully submitted and would be delivered to recipients shortly.