in reply to Comandline arguements when perl code is getting executed from command line

Pass it as a parameter, and it'll be in @ARGV.
  • Comment on Re: Comandline arguements when perl code is getting executed from command line
  • Download Code

Replies are listed 'Best First'.
Re^2: Comandline arguements when perl code is getting executed from command line
by ysth (Canon) on Jan 16, 2007 at 04:16 UTC
    Not a good idea when using the -n switch. Unless you mean a BEGIN { } block and maybe Getopt::*?
      He could use BEGIN { $type = shift(@ARGV); }, he could use -s or he could get rid of -n.
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re^2: Comandline arguements when perl code is getting executed from command line
by jesuashok (Curate) on Jan 16, 2007 at 04:14 UTC
    #!/usr/bin/ksh cat file | while read i do file_name=`echo $i | awk -F"|" '{print $1}'` #get the file_name export type=`echo $i | awk -F"|" '{print $2}'` #get the customer type + setting for the file perl -nle '/TABLE/ && print "$ARGV:$_:@ARGV"' $file_name $type done
    thanks a lot, the above too worked fine as expected.

      hi, don't you have a shell that supports $(...) to avoid backquotes `...`; the first does nest properly and the second does not. Modern shell hackers consider the second form obsolete, but yes it is portable and is probably the way to go if you do configure-like sport...

      cheers --stephan

      Not really. -n tries to open the value of $type as a file.

      By the way, won't you have a problem if $file_name or $type contains shell metacharacters?