<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Enter a variable from the cli when executing a perl script in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987405#M100152</link>
    <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;In Perl, the command line arguments appear in @ARGV and can be addressed individually as $ARGV[0], $ARGV[1], etc. for argument-1, argument-2, etc.  Note the difference from C or from the shell.&lt;BR /&gt;&lt;BR /&gt;# perl -e 'print $ARGV[0] if @ARGV;shift;print " $ARGV[0]\n" if @ARGV'  hello world  &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
    <pubDate>Mon, 26 Jun 2006 07:38:09 GMT</pubDate>
    <dc:creator>James R. Ferguson</dc:creator>
    <dc:date>2006-06-26T07:38:09Z</dc:date>
    <item>
      <title>Enter a variable from the cli when executing a perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987404#M100151</link>
      <description>&lt;BR /&gt;Hi There&lt;BR /&gt;If I may ask another silly question&lt;BR /&gt;&lt;BR /&gt;I amtrying to run the script below like I would a normal korn script, in the following format&lt;BR /&gt;&lt;BR /&gt;#./MrtgNew.pl 10.10.10.10 steve&lt;BR /&gt;&lt;BR /&gt;However for some reason it does not pick up my  variable from the command line&lt;BR /&gt;$1 being the ip address and $2 the community name. What am I doing wrong ?&lt;BR /&gt;&lt;BR /&gt;#! /usr/bin/perl -w&lt;BR /&gt;### Format  is MrtgNew ipaddress communityname&lt;BR /&gt;$NEWRTR=~$1;&lt;BR /&gt;$COMMUNITY=~$2;&lt;BR /&gt;#`mkdir /home1/mrtg/$NEWRTR`;&lt;BR /&gt;print "$1    $2 \n";&lt;BR /&gt;print " made directory for $NEWRTR and a comunity of $COMMUNITY\n";&lt;BR /&gt;sleep 10;&lt;BR /&gt;print "`/usr/local/mrtg-2/bin/cfgmaker --global WorkDir: /home1/mrtg/$NEWRTR -ifref=ip --global 'Options[_]: bits,growri&lt;BR /&gt;ght' --output /home1/mrtg/cfg/$NEWRTR.cfg $COMMUNITY@$NEWRTR`";&lt;BR /&gt;exit;&lt;BR /&gt;&lt;BR /&gt;#### end of script</description>
      <pubDate>Mon, 26 Jun 2006 07:26:48 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987404#M100151</guid>
      <dc:creator>Steve_617</dc:creator>
      <dc:date>2006-06-26T07:26:48Z</dc:date>
    </item>
    <item>
      <title>Re: Enter a variable from the cli when executing a perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987405#M100152</link>
      <description>Hi Steve:&lt;BR /&gt;&lt;BR /&gt;In Perl, the command line arguments appear in @ARGV and can be addressed individually as $ARGV[0], $ARGV[1], etc. for argument-1, argument-2, etc.  Note the difference from C or from the shell.&lt;BR /&gt;&lt;BR /&gt;# perl -e 'print $ARGV[0] if @ARGV;shift;print " $ARGV[0]\n" if @ARGV'  hello world  &lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 26 Jun 2006 07:38:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987405#M100152</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-06-26T07:38:09Z</dc:date>
    </item>
    <item>
      <title>Re: Enter a variable from the cli when executing a perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987406#M100153</link>
      <description>Well try this out&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl -w&lt;BR /&gt;&lt;BR /&gt;### Format is MrtgNew ipaddress communityname&lt;BR /&gt;$NEWRTR=$ARGV[0];&lt;BR /&gt;$COMMUNITY=$ARGV[1];&lt;BR /&gt;#`mkdir /home1/mrtg/$NEWRTR`;&lt;BR /&gt;print "$NEWRTR $COMMUNITY \n";&lt;BR /&gt;print " made directory for $NEWRTR and a comunity of $COMMUNITY\n";&lt;BR /&gt;sleep 10;&lt;BR /&gt;print "`/usr/local/mrtg-2/bin/cfgmaker --global WorkDir: /home1/mrtg/$NEWRTR -ifref=ip --global 'Options[_]: bits,growri&lt;BR /&gt;ght' --output /home1/mrtg/cfg/$NEWRTR.cfg $COMMUNITY@$NEWRTR`";&lt;BR /&gt;exit;&lt;BR /&gt;&lt;BR /&gt;#### end of script&lt;BR /&gt;</description>
      <pubDate>Mon, 26 Jun 2006 07:58:09 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987406#M100153</guid>
      <dc:creator>Jannik</dc:creator>
      <dc:date>2006-06-26T07:58:09Z</dc:date>
    </item>
    <item>
      <title>Re: Enter a variable from the cli when executing a perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987407#M100154</link>
      <description>&lt;BR /&gt;OK&lt;BR /&gt;I have tried to assign argv[0] and argv[1], in my script, but still get a blank reply.&lt;BR /&gt;&lt;BR /&gt;My script looks like this:-&lt;BR /&gt;#! /usr/bin/perl -w&lt;BR /&gt;### Format  is MrtgNew ipaddress communityname&lt;BR /&gt;$NEWRTR=$ARGV[0];&lt;BR /&gt;$COMMUNITY=$ARGV[1];&lt;BR /&gt;#`mkdir /home1/mrtg/$NEWRTR`;&lt;BR /&gt;print "$1    $2 \n";&lt;BR /&gt;print " made directory for $NEWRTR and a comunity of $COMMUNITY\n";&lt;BR /&gt;&lt;BR /&gt;exit;&lt;BR /&gt;&lt;BR /&gt;It still does not work! &lt;BR /&gt;I execute it as ./MrtgNew 10.10.10.10 steve&lt;BR /&gt;&lt;BR /&gt;Regards</description>
      <pubDate>Mon, 26 Jun 2006 07:59:25 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987407#M100154</guid>
      <dc:creator>Steve_617</dc:creator>
      <dc:date>2006-06-26T07:59:25Z</dc:date>
    </item>
    <item>
      <title>Re: Enter a variable from the cli when executing a perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987408#M100155</link>
      <description>Hi steve:&lt;BR /&gt;&lt;BR /&gt;Your problem is the use of $1 and $2.  These variables are valid when you have used a regular expression to capture data but do not otherwise represent what you want.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Mon, 26 Jun 2006 08:16:24 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987408#M100155</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-06-26T08:16:24Z</dc:date>
    </item>
    <item>
      <title>Re: Enter a variable from the cli when executing a perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987409#M100156</link>
      <description>Args do not end up in $1 and $2 in perl&lt;BR /&gt;&lt;BR /&gt;$1 in shell scripts is $ARGV[0] in perl&lt;BR /&gt;$2 in shell scripts is $ARGV[1] in perl&lt;BR /&gt;etc&lt;BR /&gt;&lt;BR /&gt;If you *really* want it in $1 and $2 (but they then get lost after the first matching regex), you can use obfuscation like&lt;BR /&gt;&lt;BR /&gt;$"="\t";"@ARGV\t"=~/^(.*?)\t(.*?)\t/;&lt;BR /&gt;&lt;BR /&gt;Now you have the first two args in $1 and $2, but I bet that the rest of your co-workers will curse you for that&lt;BR /&gt;&lt;BR /&gt;and mkdir is a builtin function. Don't escape to the shell for that. See&lt;BR /&gt;&lt;BR /&gt;# perldoc -f mkdir&lt;BR /&gt;&lt;BR /&gt;--8&amp;lt;---&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;### Format is MrtgNew ipaddress communityname&lt;BR /&gt;my ($NEWRTR, $COMMUNITY) = @ARGV;&lt;BR /&gt;mkdir "/home1/mrtg/$NEWRTR", 0777;&lt;BR /&gt;print "$NEWRTR $COMMUNITY\n";&lt;BR /&gt;print " made directory for $NEWRTR and a comunity of $COMMUNITY\n";&lt;BR /&gt;&lt;BR /&gt;exit;&lt;BR /&gt;--&amp;gt;8---&lt;BR /&gt;&lt;BR /&gt;Enjoy, Have FUN! H.Merijn</description>
      <pubDate>Mon, 26 Jun 2006 08:19:28 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987409#M100156</guid>
      <dc:creator>H.Merijn Brand (procura</dc:creator>
      <dc:date>2006-06-26T08:19:28Z</dc:date>
    </item>
    <item>
      <title>Re: Enter a variable from the cli when executing a perl script</title>
      <link>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987410#M100157</link>
      <description>Thanks all for your help.&lt;BR /&gt;This is an excelent service, and a great help&lt;BR /&gt;</description>
      <pubDate>Wed, 28 Jun 2006 06:36:15 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/enter-a-variable-from-the-cli-when-executing-a-perl-script/m-p/4987410#M100157</guid>
      <dc:creator>Steve_617</dc:creator>
      <dc:date>2006-06-28T06:36:15Z</dc:date>
    </item>
  </channel>
</rss>

