Re: read/write to command line opened as a file
Hi all, On Mon, 20 Apr 2015 17:02:22 -0500 Andy Bach wrote: > On Mon, Apr 20, 2015 at 3:32 PM, Frank K. wrote: > > > Would someone suggest a solution which would allow me to “open” a > > read/write session to a command line?? > > > perlfaq8.pod >How can I open a pipe both to and from a command? >The IPC::Open2 module (part of the standard perl distribution) is an > easy-to-use approach that internally uses pipe(), fork(), and exec() to do > the job. >Make sure you read the deadlock warnings in its documentation, > though (see IPC::Open2). See "Bidirectional Communication with Another > Process" in perlipc >and "Bidirectional Communication with Yourself" in perlipc > >You may also use the IPC::Open3 module (part of the standard perl > distribution), but be warned that it has a different order of arguments > from IPC::Open2 >(see IPC::Open3). In addition to IPC::Open2 and IPC::Open3 (which may not work too well, especially on Windows) there are also: * https://metacpan.org/release/IPC-Run * https://metacpan.org/release/Expect * https://metacpan.org/search?q=windows%20console - nothing definite here, but I remember the Windows' Console API. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ http://is.gd/KNvczZ - The FSF Announces New Versions of the GPL He says “One and one and one is three”. Got to be good‐looking ’cause he’s so hard to see. — The Beatles, “Come Together” Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: read/write to command line opened as a file
On Mon, Apr 20, 2015 at 3:32 PM, Frank K. wrote: > Would someone suggest a solution which would allow me to “open” a > read/write session to a command line?? perlfaq8.pod How can I open a pipe both to and from a command? The IPC::Open2 module (part of the standard perl distribution) is an easy-to-use approach that internally uses pipe(), fork(), and exec() to do the job. Make sure you read the deadlock warnings in its documentation, though (see IPC::Open2). See "Bidirectional Communication with Another Process" in perlipc and "Bidirectional Communication with Yourself" in perlipc You may also use the IPC::Open3 module (part of the standard perl distribution), but be warned that it has a different order of arguments from IPC::Open2 (see IPC::Open3). -- a Andy Bach, afb...@gmail.com 608 658-1890 cell 608 261-5738 wk
read/write to command line opened as a file
Ok, I am trying to do something I initially thought would be fairly easy to do but am running into lots of trouble. I have a db2 instance running on a Windows 2k8r2 Enterprise server, using ActivePerl V5.8.. I wanted to open a file handle in read/write mode to run cmd.exe.. I then need to write several commands to the handle and read the output of each command.. Would someone suggest a solution which would allow me to "open" a read/write session to a command line?? Thanks in advance.. flk k
Windows Command-Line Arguments; Secrets or Stitching Them Together
Hello, I've been writing more and more utilities in Perl and using them both in Windows and GNU/Linux. Since I'm so used to UNIX shells and terminals, cmd.exe obviously leaves much to be desired, but I don't care for Cygwin or MSYS environments. They each have their own strengths and weaknesses and none of them are fully usable. So anyway I've been using PyCmd as a wrapper around cmd.exe. It basically adds sensible tab completion and history recall. One thing that it doesn't do is consider .pl files (or extensionless files with a shebang, naturally) executable in Windows. So you can't tab complete these programs. The Windows shell itself seems to associate .pl with Strawberry Perl and it does seem to work via the PATH environment variable. There's just no tab completion. So what I usually do (and it looks like ExtUtils::MakeMaker does too) is wrap the Perl programs in a .bat or .cmd script. The problem then is obviously preserving arguments with whitespace or special characters when passing them onward to the Perl program. In e.g., bash you can just do "$@" and it will expand to quoted arguments, correctly passing them on, but no such mechanism exists for cmd.exe that I am aware of. %* is substituted for the command line arguments, but they aren't quoted or escaped so they are not preserved. You could hard-code up to 9 arguments with "%1" "%2" ... "%n", but then you'll be passing always 9 arguments, whether there are 3 or 12. So I'm curious what other Perl users do when they're stuck in Windows (or similar platforms with sub-par shells). Does anybody have any tricks that work well, or know of any existing CPAN modules to make this easier? The other day I found myself having trouble with a simple little program that "sanitizes" file names by removing whitespace and certain special characters (things that are inconvenient from the command shell). It just processes @ARGV, but I'd find myself passing it things like "foo\bar baz.txt". Naturally, the wrapper .cmd program would pass that on as "foo\bar" "baz.txt" and the Perl program wouldn't work. For this particular case I decided to write some code to try to "guess" what was originally meant and stitch the arguments back together. For my amusement I'll include the WIP module that it resulted in for your code review and criticism. I just hacked it together over a couple of days in a few hours. It basically does a few things: it tries to guess when something is a file path and stitch it back together, it tries to preserve options as individual arguments, and it tries to simulate single-quoting and join arguments based on single-quote wrappers. So if it finds an argument that looks like a filename with an extension then it will join it with previous arguments to form a full path. ('foo', 'bar', 'baz.txt') will become 'foo bar baz.txt'. If it finds anything that begins with a '-' then it considers it an option and leaves it on its own. ('foo', '-bar', 'baz.txt') will not be modified because '-bar' is preserved as a lone argument. If an argument begins with a single-quote then it considers it a single-quoted argument and joins it with subsequent arguments until it finds an argument that ends with a single-quote. So ("foo", "'bar", "baz'", "bak.txt") will become ('foo', 'bar baz', 'bak.txt'). As a special rule, if it finds ++ then it stops guessing and considers the subsequent arguments to be correct as is. Take a look and let me know what you think about it. And keep an eye out for velociraptors[1]. #!/usr/bin/env perl # # h4x: Attempt to stitch arguments with spaces in them back together. # Obviously will result in a lot of false positives. # package GuessArgs; use v5.016; use strict; use utf8; use version; use warnings; BEGIN { our $VERSION = version->declare('0.0.1'); } use Data::Dumper; use File::Glob qw/:bsd_glob/; my $debug = 0; my $main = sub { $debug = 1; guess_args(\@ARGV); say Dumper \@ARGV; }; $main->() unless caller(); # Attempts to stich arguments back together for platforms^H that # 'struggle' to preserve arguments with whitespace. sub guess_args($) { my ($orig_args) = @_; return @$orig_args unless $debug || $^O eq 'MSWin32'; my @args; my $arg; my $literal = 0; my $quoted = 0; my $append_arg = sub { if(defined $arg) { $arg .= ' ' . $_; } else { $arg = $_; } }; my $flush_arg = sub { if(defined $arg) { push @args, $arg; undef $arg; } }; for (@$orig_args) { # h4x: ++ is used to terminate guessing and proc
Re: Regex behavior in command line
I overlooked the missing single quotes, Thanks! -Jon
Re: Regex behavior in command line
On 31/05/2012 18:23, Jon Forsyth wrote: I'm using the following line in Terminal, on OSX Lion, but I can't seem to match parentheses '()': perl -n -e 'print if(/\\(Submit\\)/)' visits/admin_add.ctp I tried with one backslash in front of each '(' ')' as well to no avail. If I remove the '\'s and '()' the match is printed like so: end('Submit');?> My purpose is to make sure I'm matching the correct lines including the '()', then to alter the code to perform a search and replace on the matches). Something like: perl -p -i.bak -e 's/PATTERN/REPLACE/g' INPUT Hi Jon Backslashes within a single-quoted command-line string don't need escaping, so a single backslash before each parenthesis is correct. But from your output it seems you have omitted the single-quotes around 'Submit' from your pattern, and that is why it isn't matching. With a conflict of single quotes and backslashes it is probably better if you write a short program than try to get it working on the command line, but perl -n -e 'print if(/\(\'Submit\'\)/)' visits/admin_add.ctp or perl -n -e "print if(/\\('Submit'\\)/)" visits/admin_add.ctp are the correct forms for use on the command-line. HTH, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Regex behavior in command line
On 12-05-31 01:23 PM, Jon Forsyth wrote: Hello, I'm using the following line in Terminal, on OSX Lion, but I can't seem to match parentheses '()': perl -n -e 'print if(/\\(Submit\\)/)' visits/admin_add.ctp I tried with one backslash in front of each '(' ')' as well to no avail. If I remove the '\'s and '()' the match is printed like so: end('Submit');?> My purpose is to make sure I'm matching the correct lines including the '()', then to alter the code to perform a search and replace on the matches). Something like: perl -p -i.bak -e 's/PATTERN/REPLACE/g' INPUT Thanks! Mine works with one backslash: $ perl -n -e 'print"\t$_" if(/\(Submit\)/)' Submit (Submit) (Submit) This is a test Submit will not repeat This is a test (Submit) will repeat This is a test (Submit) will repeat ^D -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. _Perl links_ official site : http://www.perl.org/ beginners' help : http://learn.perl.org/faq/beginners.html advance help: http://perlmonks.org/ documentation : http://perldoc.perl.org/ news: http://perlsphere.net/ repository : http://www.cpan.org/ blog: http://blogs.perl.org/ regional groups : http://www.pm.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Regex behavior in command line
Hello, I'm using the following line in Terminal, on OSX Lion, but I can't seem to match parentheses '()': perl -n -e 'print if(/\\(Submit\\)/)' visits/admin_add.ctp I tried with one backslash in front of each '(' ')' as well to no avail. If I remove the '\'s and '()' the match is printed like so: end('Submit');?> My purpose is to make sure I'm matching the correct lines including the '()', then to alter the code to perform a search and replace on the matches). Something like: perl -p -i.bak -e 's/PATTERN/REPLACE/g' INPUT Thanks! Jon
Re: read from command line
Thanks for both of you. Your guys are great. Best regards, -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: read from command line
On Sat, Mar 3, 2012 at 9:08 AM, lina wrote: > $ perl extract.pl try.tex > Bareword "filename" not allowed while "strict subs" in use at extract.pl line > 8. > Execution of extract.pl aborted due to compilation errors. > > > #!/usr/bin/env perl > > use strict; > use warnings; > > my $filename = $ARGV[0] ; > You used 'filename', not '$filename' 'filename' is a bareword - not a perl variable, or a string. > open FILE, "<", filename or die $!; > > my @line = ; > You just read the entire file into the @line array. If that is your intent, you need to loop on @lines. Otherwise, if you wish to read the file line by line, omit the line my @line = ; > while () { > print $_; > } > > > I tried mf $filename = also not work. > > Thanks ahead for any suggestions, > > Best regards, > HTH, Ken -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: read from command line
On 2012-03-03 09:08, lina wrote: $ perl extract.pl try.tex Bareword "filename" not allowed while "strict subs" in use at extract.pl line 8. Execution of extract.pl aborted due to compilation errors. #!/usr/bin/env perl use strict; use warnings; Good. my $filename = $ARGV[0] ; open FILE, "<", filename or die $!; You're trying to read from a bareword 'filename', and not $filename :) Some would say to rewrite that open statement like this: open my $file, '<', $filename or die "Can't open $filename: $!"; my @line = ; That sucks in the entire file into @line all at once, so remove it. while () { print $_; } the while() block should be rewritten as such: while ( my $line = <$file> ){ print $line; } Steve -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
read from command line
$ perl extract.pl try.tex Bareword "filename" not allowed while "strict subs" in use at extract.pl line 8. Execution of extract.pl aborted due to compilation errors. #!/usr/bin/env perl use strict; use warnings; my $filename = $ARGV[0] ; open FILE, "<", filename or die $!; my @line = ; while () { print $_; } I tried mf $filename = also not work. Thanks ahead for any suggestions, Best regards, -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Command line perl to stat a file
On 2012-02-11 20:33, Harry Putnam wrote: Kevin Spencer writes: On Fri, Feb 10, 2012 at 10:52 AM, Harry Putnam wrote: But these command line attempts fail: (all on one line) perl -e 'my ($seven, $nine) = (stat('./SweetwatterPk-016.jpg'))[7, 9]; print "$seven and $nine"' output: syntax error at -e line 1, near "stat(." Search pattern not terminated at -e line 1. It's the use of single quotes inside your stat() command. You've already opened a single quote after your perl -e statement. Try switching the inner single quotes to double quotes and you'll no longer get the syntax error. Thanks, and yes that works now. At least I was kinda sorta on the right track there. But I should have thought to try double quotes. Then there is q and qq. -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Command line perl to stat a file
Kevin Spencer writes: > On Fri, Feb 10, 2012 at 10:52 AM, Harry Putnam wrote: >> >> But these command line attempts fail: >> >> (all on one line) >> perl -e 'my ($seven, $nine) = >> (stat('./SweetwatterPk-016.jpg'))[7, 9]; >> print "$seven and $nine"' >> >> output: >> syntax error at -e line 1, near "stat(." >> Search pattern not terminated at -e line 1. > > It's the use of single quotes inside your stat() command. You've > already opened a single quote after your perl -e statement. Try > switching the inner single quotes to double quotes and you'll no > longer get the syntax error. Thanks, and yes that works now. At least I was kinda sorta on the right track there. But I should have thought to try double quotes. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Command line perl to stat a file
Rob Dixon writes: > Something like this perhaps? > > perl -e "print join ' and ', (stat shift)[7,9]" ./SweetwaterPk-016.jpg Nice... yes Thanks > But I would think the modification time (stat 9) wouldn't be of much > use without formatting it. In this case it was just for a quick command line way to visually compare epochal dates. So epochal is what is desired. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Command line perl to stat a file
On Fri, Feb 10, 2012 at 10:52 AM, Harry Putnam wrote: > > But these command line attempts fail: > > (all on one line) > perl -e 'my ($seven, $nine) = > (stat('./SweetwatterPk-016.jpg'))[7, 9]; > print "$seven and $nine"' > > output: > syntax error at -e line 1, near "stat(." > Search pattern not terminated at -e line 1. It's the use of single quotes inside your stat() command. You've already opened a single quote after your perl -e statement. Try switching the inner single quotes to double quotes and you'll no longer get the syntax error. Hope that helps. -- Kevin. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Command line perl to stat a file
On 10/02/2012 17:52, Harry Putnam wrote: This script: --- 8< snip -- 8< snip -- 8 Something like this perhaps? perl -e "print join ' and ', (stat shift)[7,9]" ./SweetwaterPk-016.jpg But I would think the modification time (stat 9) wouldn't be of much use without formatting it. HTH, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Command line perl to stat a file
This script: --- 8< snip -- 8< snip -- 8http://learn.perl.org/
Re: perl as command line
W dniu 2011-05-24 06:11, vishesh kumar pisze: Hi Members, I am a linux system admin. I want to use perl as a command line like sed and awk. generally, you might be interested in http://minimalperl.com/. HTH Irek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl as command line
Thanks Jim Now i understood completely. Very good explanation. On Fri, May 27, 2011 at 10:45 AM, Jim Gibson wrote: > At 10:28 AM +0530 5/27/11, vishesh kumar wrote: > >> Hi Jim >> > > You should address all of your questions to the list as a whole. That way > you will get smarter people than me helping you. > > > echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/' >> >> Giving desired result, but i wonder what is use of ? in this expression >> > > Did you try it without the question mark? If you do, you will see the > affect of "greedy" quantifiers. Without the question mark, the first '.*' > matches the longest string. This means that you won't get the full IP > address, just the minimal part at its rear end that matches the > '\d+\.[\d.]+' part, which could be '1.1' for example. With the '?', the > initial '.*' matches only the part of the string before the first digit, and > the whole IP address is matched and captured. > > -- http://linuxmantra.com
Re: perl as command line
At 10:28 AM +0530 5/27/11, vishesh kumar wrote: Hi Jim You should address all of your questions to the list as a whole. That way you will get smarter people than me helping you. echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/' Giving desired result, but i wonder what is use of ? in this expression Did you try it without the question mark? If you do, you will see the affect of "greedy" quantifiers. Without the question mark, the first '.*' matches the longest string. This means that you won't get the full IP address, just the minimal part at its rear end that matches the '\d+\.[\d.]+' part, which could be '1.1' for example. With the '?', the initial '.*' matches only the part of the string before the first digit, and the whole IP address is matched and captured. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl as command line
Hi Jim echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/' Giving desired result, but i wonder what is use of ? in this expression On Tue, May 24, 2011 at 11:59 AM, Jim Gibson wrote: > At 9:41 AM +0530 5/24/11, vishesh kumar wrote: > >> Hi Members, >> >> I am a linux system admin. I want to use perl as a command line like sed >> and awk. >> For example suppose , i need to extract IP Addr from a string or file >> using >> regrex >> i mean >> str="hello ip is 192.168.2.1 and data is xxx" >> And i want ip addr only using Regex >> echo $str | perl -pe ?? >> > > Try this: > > echo $str | perl -pe 's/[^\d.]//g' > > If your line has other numbers, this will get the first contiguous set: > > echo $str | perl -pe 's/.*?([\d.]+).*/$1/' > > This will make sure there is at least one dot in the substring extracted: > > echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/' > > -- http://linuxmantra.com
Re: perl as command line
Thanks Jim Your suggestion working great !!! On Tue, May 24, 2011 at 11:59 AM, Jim Gibson wrote: > echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/' -- http://linuxmantra.com
Re: perl as command line
Hi Vishesh, On Tuesday 24 May 2011 07:11:45 vishesh kumar wrote: > Hi Members, > > I am a linux system admin. I want to use perl as a command line like sed > and awk. > For example suppose , i need to extract IP Addr from a string or file using > regrex > i mean > str="hello ip is 192.168.2.1 and data is xxx" > And i want ip addr only using Regex > echo $str | perl -pe ?? > Please see: http://search.cpan.org/dist/Regexp-Common/ namely http://search.cpan.org/perldoc?Regexp::Common::net . Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ First stop for Perl beginners - http://perl-begin.org/ "I'm not straight - I'm Israeli." Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl as command line
At 9:41 AM +0530 5/24/11, vishesh kumar wrote: Hi Members, I am a linux system admin. I want to use perl as a command line like sed and awk. For example suppose , i need to extract IP Addr from a string or file using regrex i mean str="hello ip is 192.168.2.1 and data is xxx" And i want ip addr only using Regex echo $str | perl -pe ?? Try this: echo $str | perl -pe 's/[^\d.]//g' If your line has other numbers, this will get the first contiguous set: echo $str | perl -pe 's/.*?([\d.]+).*/$1/' This will make sure there is at least one dot in the substring extracted: echo $str | perl -pe 's/.*?(\d+\.[\d.]+).*/$1/' -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
perl as command line
Hi Members, I am a linux system admin. I want to use perl as a command line like sed and awk. For example suppose , i need to extract IP Addr from a string or file using regrex i mean str="hello ip is 192.168.2.1 and data is xxx" And i want ip addr only using Regex echo $str | perl -pe ?? Please guide me, --
Re: Some explanation please -- iterating thru command line arguments
Hi Brandon, Thanks ... using the cat and pipe looks "cleaner" ... I will try that one ... thanks On Fri, Jul 23, 2010 at 4:53 AM, Brandon McCaig wrote: > On Wed, Jul 21, 2010 at 1:17 PM, newbie01 perl > wrote: > > Does $_ contains the following values on each iteration? > > > > mail_smtp.pl > > -r > > ${MAILFROM} > > -s > > "$subject_line TEST EMAIL" > > supportm...@test.com > > < > > /tmp/test_email.txt > > Just to clarify the end of the command line: > > mail_smtp.pl -r ${MAILFROM} \ >-s "$subject_line TEST EMAIL" \ > supportm...@test.com < /tmp/test_email.txt > > The '< /tmp/test_email.txt' part is not extra arguments passed to the > script. That is a file redirection operator in the shell[1], used to > write the file to the script's standard input stream. The script > accepts an option -f to specify the file to retrieve the message data > from, but if none is specified then it defaults to - which is > basically an alias for STDIN.[2] > > The same thing can be accomplished with a pipe: > > cat /tmp/test_email.txt | mail_smtp.pl -r ${MAILFROM} \ >-s "$subject_line TEST EMAIL" supportm...@test.com > > So the script wouldn't see arguments equal to '<' or > '/tmp/test_email.txt'. The shell will handle those for it automatically. > > > [1] http://en.wikipedia.org/wiki/Redirection_(computing) > [2] perldoc -f open > > -- > Brandon McCaig > V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. > Castopulence Software <http://www.castopulence.org/> < > bamcc...@castopulence.org> >
Re: Some explanation please -- iterating thru command line arguments
On Wed, Jul 21, 2010 at 1:17 PM, newbie01 perl wrote: > Does $_ contains the following values on each iteration? > > mail_smtp.pl > -r > ${MAILFROM} > -s > "$subject_line TEST EMAIL" > supportm...@test.com > < > /tmp/test_email.txt Just to clarify the end of the command line: mail_smtp.pl -r ${MAILFROM} \ -s "$subject_line TEST EMAIL" \ supportm...@test.com < /tmp/test_email.txt The '< /tmp/test_email.txt' part is not extra arguments passed to the script. That is a file redirection operator in the shell[1], used to write the file to the script's standard input stream. The script accepts an option -f to specify the file to retrieve the message data from, but if none is specified then it defaults to - which is basically an alias for STDIN.[2] The same thing can be accomplished with a pipe: cat /tmp/test_email.txt | mail_smtp.pl -r ${MAILFROM} \ -s "$subject_line TEST EMAIL" supportm...@test.com So the script wouldn't see arguments equal to '<' or '/tmp/test_email.txt'. The shell will handle those for it automatically. [1] http://en.wikipedia.org/wiki/Redirection_(computing) [2] perldoc -f open -- Brandon McCaig V zrna gur orfg jvgu jung V fnl. Vg qbrfa'g nyjnlf fbhaq gung jnl. Castopulence Software <http://www.castopulence.org/> -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Some explanation please -- iterating thru command line arguments
newbie01 perl wrote: Hi all especially Perl teachers if anyone is ... :-) I just want to know if someone can provide some explanation on how does the argument iterator sub-routine below work. The Perl script is called from a UNIX Korn script as below: mail_smtp.pl -r ${MAILFROM} -s "$subject_line TEST EMAIL" supportm...@test.com< /tmp/test_email.txt The Perl script is working and SMTP mail is working. Am just trying to understand how the getval sub-routine is parsing the command line arguments. the getval subroutine is as below. = sub getval { my $refVal = ''; foreach $var(@ARGV) { if ($refVal ne '') { $$refVal = $var; $refVal = ''; } else { $_ = $var; if (/-r/ ) { $refVal=\$fromUser; } elsif (/-f/) { $refVal=\$dataFile; } elsif (/-s/) { $refVal=\$subject; } else { @toUser = split(/[\;,]/,$var); } } } } = The portion that am confused at is at the following lines: $$refVal = $var; and $_ = $var; if (/-r/ ) { $refVal=\$fromUser; } When @ARGV is at the '-r' element the $refVal=\$fromUser assigns a reference from $fromUser to the variable $refVal and then the next time through the loop when @ARGV is the element just past '-r' $fromUser is dereferenced through $$refVal and is assigned the current element of @ARGV. You are probably better off just using Getopt::Std Does "if (/-r/ )" means "ignore" all command line that begins with a hyphen but reference by value the next command line argument after them? In this case "if (/-r/ )" is just short for "if ($var =~ /-r/ )" but for some "cute" reason the programmer decided to use $_ instead of $var. Also, /-r/ matches the string '-r' *anywhere* in $_, not just at the beginning. It would more properly be written as "if (/\A-r\z/ )" or even "if ( $_ eq '-r' )". Does $_ contains the following values on each iteration? mail_smtp.pl -r ${MAILFROM} -s "$subject_line TEST EMAIL" supportm...@test.com < /tmp/test_email.txt Any "explanation" on this will be very much appreciated. Am going nuts trying to understand how the iteration functions although am glad it is functioning. Thanks in advance. === mail_smtp.pl source code below: === #!/usr/bin/perl -w use warnings; use strict; use Net::SMTP; use FileHandle; # global variables my $fromUser = $ENV{USER}; my @toUser = {}; This is assigning a hash reference to the first element of @toUser which makes little sense. my $smtpSvr = '192.168.3.11'; my $subject = ''; my $dataFile = ''; #$mailBody = ''; sub getval { my $refVal = ''; foreach $var(@ARGV) { if ($refVal ne '') { $$refVal = $var; $refVal = ''; } else { $_ = $var; if (/-r/ ) { $refVal=\$fromUser; } elsif (/-f/) { $refVal=\$dataFile; } elsif (/-s/) { $refVal=\$subject; } else { @toUser = split(/[\;,]/,$var); } } } } # main getval(@ARGV); This is passing the array @ARGV to the @_ array inside the subroutine but you don't use the @_ array inside the subroutine so why do it? if (@toUser ne {}) { That statement is useless and doesn't do what the programmer seems to think it is doing. An array in scalar context will return the number of elements in the array, which at this point is 1. So '1' will be compared to the textual representation of an anonymous hash which is something like 'HASH(0x9ec8818)' and the two will *never* be equal. Even if the programmer just compared the first element of @toUser to an anonymous hash they would *never* be equal. What the programmer should have done is define the array without any elements: my @toUser; And then test the a
Re: Some explanation please -- iterating thru command line arguments
On 7/21/10 Wed Jul 21, 2010 10:17 AM, "newbie01 perl" scribbled: > Hi all especially Perl teachers if anyone is ... :-) > > I just want to know if someone can provide some explanation on how does the > argument iterator sub-routine below work. The Perl script is called from a > UNIX Korn script as below: > > mail_smtp.pl -r ${MAILFROM} -s "$subject_line TEST EMAIL" > supportm...@test.com < /tmp/test_email.txt > > The Perl script is working and SMTP mail is working. Am just trying to > understand how the getval sub-routine is parsing the command line arguments. > the getval subroutine is as below. > > = > > sub getval { > my $refVal = ''; > foreach $var(@ARGV) { > if ($refVal ne '') { > $$refVal = $var; > $refVal = ''; > } > else { > $_ = $var; > if (/-r/ ) { > $refVal=\$fromUser; > } > elsif (/-f/) { > $refVal=\$dataFile; > } > elsif (/-s/) { > $refVal=\$subject; > } > else { > @toUser = split(/[\;,]/,$var); > } > > } > } > } > > = > > The portion that am confused at is at the following lines: > > $$refVal = $var; That line assigns (copies) the contents of the $var variable to the location referenced by the $refVal pointer. This will be either $fromUser, $dataFile, or $subject, depending upon the option entered (-r, -f, or -s, respectively). > > and > > $_ = $var; > if (/-r/ ) { > $refVal=\$fromUser; > } The above lines copy the contents of $var to $_, tests if $_ contains the string '-r', and, if it does, sets $refVal to 'refer' to $fromUser. A better form would be to test $var directly: if( $var =~ /-r/ ) { $refVal = \$fromUser; } > Does $_ contains the following values on each iteration? $var, and hence $_ (since it is a copy of $var), will contain the elements of the @ARGV array, one per iteration of the foreach loop. If you use the GetOptions module, you can replace the getval subroutine with something like this (untested): use Getopt::Long; GetOptions( 'r=s' => \$fromUser, 'f=s' => \$dataFile, 's=s' => \$subject ); push(@toUser, split/[;,]/) for @ARGV; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Some explanation please -- iterating thru command line arguments
Hi all especially Perl teachers if anyone is ... :-) I just want to know if someone can provide some explanation on how does the argument iterator sub-routine below work. The Perl script is called from a UNIX Korn script as below: mail_smtp.pl -r ${MAILFROM} -s "$subject_line TEST EMAIL" supportm...@test.com < /tmp/test_email.txt The Perl script is working and SMTP mail is working. Am just trying to understand how the getval sub-routine is parsing the command line arguments. the getval subroutine is as below. = sub getval { my $refVal = ''; foreach $var(@ARGV) { if ($refVal ne '') { $$refVal = $var; $refVal = ''; } else { $_ = $var; if (/-r/ ) { $refVal=\$fromUser; } elsif (/-f/) { $refVal=\$dataFile; } elsif (/-s/) { $refVal=\$subject; } else { @toUser = split(/[\;,]/,$var); } } } } = The portion that am confused at is at the following lines: $$refVal = $var; and $_ = $var; if (/-r/ ) { $refVal=\$fromUser; } Does "if (/-r/ )" means "ignore" all command line that begins with a hyphen but reference by value the next command line argument after them? Does $_ contains the following values on each iteration? mail_smtp.pl -r ${MAILFROM} -s "$subject_line TEST EMAIL" supportm...@test.com < /tmp/test_email.txt Any "explanation" on this will be very much appreciated. Am going nuts trying to understand how the iteration functions although am glad it is functioning. Thanks in advance. === mail_smtp.pl source code below: === #!/usr/bin/perl -w use Net::SMTP; use FileHandle; # global variables my $fromUser = $ENV{USER}; my @toUser = {}; my $smtpSvr = '192.168.3.11'; my $subject = ''; my $dataFile = ''; #$mailBody = ''; sub getval { my $refVal = ''; foreach $var(@ARGV) { if ($refVal ne '') { $$refVal = $var; $refVal = ''; } else { $_ = $var; if (/-r/ ) { $refVal=\$fromUser; } elsif (/-f/) { $refVal=\$dataFile; } elsif (/-s/) { $refVal=\$subject; } else { @toUser = split(/[\;,]/,$var); } } } } # main getval(@ARGV); if (@toUser ne {}) { if ($dataFile eq '') { $dataFile = '-'; } open(my $inFile, "< $dataFile"); $smtp = Net::SMTP->new($smtpSvr); $smtp->mail($fromUser); $smtp->to(@toUser); $smtp->data(); $smtp->datasend("From:$fromUser\n"); $smtp->datasend("To:".join(';',@toUser)."\n"); if ($subject ne '') { $smtp->datasend("Subject:$subject\n"); } while (<$inFile>) { if (/^\.$/) { last; } else { $smtp->datasend($_); } } close($inFile); $smtp->dataend(); $smtp->quit; }
Re: passing command-line arg containing '@'
>I need to pass an command-line arg that is a string which contains the '@'. Is there any way to do this and also 'tell' Perl not to interpret this as other than a '@' character? > >Thx. Hi, Perl would not do anything with command-line arguments unless you tell it otherwise. Check if you are using the EXPR form of eval to modify the argument list. perl -MData::Dumper -le 'print Dumper \...@argv' @this @should @work __Output__ $VAR1 = [ '@this', '@should', '@work' ]; Regards, Alan Haggai Alavi. -- The difference makes the difference. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: passing command-line arg containing '@'
On 12/9/09 Wed Dec 9, 2009 6:01 PM, "Tony Esposito" scribbled: > I need to pass an command-line arg that is a string which contains the '@'. > Is there any way to do this and also 'tell' Perl not to interpret this as > other than a '@' character? The '@' character is only special in Perl source code statements. Command-line arguments are data. Your shell will put the command-line argument containing a '@' character into one of the elements of the @ARGV array. You can use that value as it is: % perl -e 'print qq(@ARGV\n);' a...@a b...@b c...@c a...@a b...@b c...@c -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
passing command-line arg containing '@'
I need to pass an command-line arg that is a string which contains the '@'. Is there any way to do this and also 'tell' Perl not to interpret this as other than a '@' character? Thx.
Re: __DATA__ in command line
OK thank you both, I got it. 2009/11/6 Shawn H Corey : > 兰花仙子 wrote: >> Hello, >> >> doesn't one-liner Perl command support __DATA__ handler? >> Just found this: >> >> # perl -e 'while(){ print } >>> __DATA__ >>> abc >>> 123 >>> def >>> ' >> >> run without any output. >> > > > $ perl -MO=Deparse -e 'while(){ print } >>> __DATA__ >>> abc >>> ' > while (defined($_ = )) { >print $_; > } > __DATA__ > -e syntax OK > > With the -e option, perl reads whatever follows as the script. The > parser, however, stops reading when it reaches a line with __DATA__ or > __END__. It ignores the rest. So when it runs, it thinks there nothing > after the __DATA__. > > > -- > Just my 0.0002 million dollars worth, > Shawn > > Programming is as much about organization and communication > as it is about coding. > > I like Perl; it's the only language where you can bless your > thingy. > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: __DATA__ in command line
兰花仙子 wrote: > Hello, > > doesn't one-liner Perl command support __DATA__ handler? > Just found this: > > # perl -e 'while(){ print } >> __DATA__ >> abc >> 123 >> def >> ' > > run without any output. > $ perl -MO=Deparse -e 'while(){ print } >> __DATA__ >> abc >> ' while (defined($_ = )) { print $_; } __DATA__ -e syntax OK With the -e option, perl reads whatever follows as the script. The parser, however, stops reading when it reaches a line with __DATA__ or __END__. It ignores the rest. So when it runs, it thinks there nothing after the __DATA__. -- Just my 0.0002 million dollars worth, Shawn Programming is as much about organization and communication as it is about coding. I like Perl; it's the only language where you can bless your thingy. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: __DATA__ in command line
À¼»¨ÏÉ×Ó wrote: Hello, Hello, doesn't one-liner Perl command support __DATA__ handler? No. It only works in an actual file located on a real file system. Just found this: # perl -e 'while(){ print } __DATA__ abc 123 def ' run without any output. You could always do it like this: perl -e' my $data = <; ' John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
__DATA__ in command line
Hello, doesn't one-liner Perl command support __DATA__ handler? Just found this: # perl -e 'while(){ print } > __DATA__ > abc > 123 > def > ' run without any output. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: command line perldoc and Padre, the Perl IDE
On Thu, Sep 10, 2009 at 13:54, Gabor Szabo wrote: snip > There is the new perlopref document by Chas. Owens who is also on > this list. That's great. Thanks Chas! That will be able to explain > certain expressions such as &&. > > I am sure he will be happy to get some help from you. > See http://github.com/cowens/perlopref snip Due to being sick on Tuesday, I was able to get enough time to mostly finish the first draft of it. There are a few operators that were not listed in the Operator Precedence and Associativity section of perlop that need to be added (like the filetest operators). What is really needed now is a critical reading by two groups of people: Perl Beginners and Perl Gurus. The first to see if the document is complete enough and written in such a way that it is clear what each operator does, and the second to catch any mistakes I may have inadvertently slipped in (there was a nasty one in the description of && where I described the operator completely incorrectly). -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
command line perldoc and Padre, the Perl IDE
perldoc has all sorts of problems, it is hard to use to people who don't yet know how to use it and it does not give you a useful answer to many questions. It gives you a correct answer, it is just not very useful to beginners. tryperldoc -f open It has a long explanation on all kinds of cases while the beginner - IMHO - wants a simple example on how to open a file. Later s/he might want to read more but first s/he wants to get the job done. In addition you have to understand when to use -f , when -q and there is no way to get information on $. or on the any of the words 'while', 'for', 'and' or '&&'. Even http://perldoc.perl.org/ does not yet find these. You can install Pod::Perldoc 3.15 (but of course a beginner first needs to learn how to install a module which is not trivial) and then you can use the new meaning of the -v option: perldoc -v '$.' and I think on windows it needs to be perldoc -v "$." but of course most of the windows people will freak out if they need to use the command line and I don't blame them. I hate to use the Windows command shell as well. That's an improvement but it still does not give you an answer on the words and expressions I mentioned above. There is the new perlopref document by Chas. Owens who is also on this list. That's great. Thanks Chas! That will be able to explain certain expressions such as &&. I am sure he will be happy to get some help from you. See http://github.com/cowens/perlopref In Padre we try to hide all that complexity under one key (currently F2) so you already get explanation on things like $. or && It still does not know what is !! but I am sure it will learn. I am also hoping to have the ability to get help on things like $_[0] Explaining that it is an element of @_ even if the user highlighted the $_ part only. I would like to see an explanation on $VERSION or just $somevar and I guess it should also understand constructs such as $$_ and be able to explain them. It would be great if people on this list could help us either by trying Padre and telling us what is still missing or by writing some documentations or by implementing the code that understands the expressions. Padre can be found on http://padre.perlide.org/ and you can talk to the Padre developers either via #padre on irc.perl.org or on our mailing list (See http://padre.perlide.org/contact.html ) regards Gabor -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Getting STDIN filename from command line
On Thu, May 21, 2009 at 12:44, Tony Esposito wrote: > Hello, > > Given the command line: > > perl myperl.plx < myfile.txt > > is there anyway from within the Perl script to capture the redirected STDIN > filename (i.e., myfile.txt)? > > OS: WinXP SPSP3 > Perl: 5.8.8 for Win32 from ActiveState snip No, because the shell is piping the data to the program. Even if you could try you would run into problems with something like this perl -pe 'print' <(cat *.pl) -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Getting STDIN filename from command line
Hello, Given the command line: perl myperl.plx < myfile.txt is there anyway from within the Perl script to capture the redirected STDIN filename (i.e., myfile.txt)? OS: WinXP SPSP3 Perl: 5.8.8 for Win32 from ActiveState Thx.
Re: One liner to generate truly random passwords from command line
On Fri, Nov 28, 2008 at 22:21, John W. Krahn <[EMAIL PROTECTED]> wrote: > Chas. Owens wrote: >> >> On Fri, Nov 28, 2008 at 10:28, John W. Krahn <[EMAIL PROTECTED]> wrote: >> snip >>> >>> perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' >> >> snip >> >> Perl Golf time: >> >> perl -le'print map chr+(33..126)[rand 94],1..8' > > $ perl -le'print map chr+(33..126)[rand 94],1..8' > Warning: Use of "chr" without parentheses is ambiguous at -e line 1. Yeah, I found it odd that it threw that warning without warnings turned on, but it still works; I wonder if that is a bug. Adding the parenthesis (and dropping the + since it is no longer needed to prevent (33..126) from looking like the arguments to chr) only adds one more character: perl -le'print map chr((33..126)[rand 94]),1..8' Also, the more confusing variant: perl -le'print+map+chr((33..126)[rand 94]),1..8' -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: One liner to generate truly random passwords from command line
Chas. Owens wrote: On Fri, Nov 28, 2008 at 10:28, John W. Krahn <[EMAIL PROTECTED]> wrote: snip perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' snip Perl Golf time: perl -le'print map chr+(33..126)[rand 94],1..8' $ perl -le'print map chr+(33..126)[rand 94],1..8' Warning: Use of "chr" without parentheses is ambiguous at -e line 1. John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: One liner to generate truly random passwords from command line
On Fri, Nov 28, 2008 at 10:28, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' snip Perl Golf time: perl -le'print map chr+(33..126)[rand 94],1..8' -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: One liner to generate truly random passwords from command line
On Thu, Nov 27, 2008 at 15:04, Yimin Rong <[EMAIL PROTECTED]> wrote: > wget -q -O - "http://random.org/integers/? > num=8&min=33&max=126&col=8&base=16&format=plain&rnd=new" | perl -ne > 'foreach (split(/\t/, $_)) {print chr(hex($_));} print "\n"' > > wget reads web pages > random.org generates random numbers using atmospheric noise > perl splits the input into tokens and converts Except you have transmitted your random number in cleartext over the net. As an attacker, I could be sniffing for http traffic (say with a proxy installed at your ISP) going/coming from random.org. Once I had that traffic I could try the random numbers in them (after conversion with your algorithm) as passwords on your system. Also, really random strings are hard to remember, which means you will write it down. Now it is susceptible to theft or search warrant. A much better solution is to use a passphrase made out of random words from a dict file. An eight charcter random password made up of a-z, A-Z, 0-9, !, @, #, $, %, ^, &, *, (, and ) gives you a search space of 72^8 (roughly 10^14) passwords. A three word passphrase from a dict file with 234,936 words (OS X's /usr/share/dict/words) gives you a search space of 234,936^3 (roughly 10^16) and an average search space of around 26^30 (10^42) (if they don't know you are using a passphrase. Which would you rather remember "abear Laotian semimembranous" (I am imagining a Laotian bear that stuff is passing through) or "WeIBHfKk"? If you bump the number of words in the passphrase up to four you get a password that is stronger than an eleven character password: "hlWVSm0nm8" vs "freakery hoary inflexive Solomonic" (a wise but inflexible old man who gets up to strange stuff). -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: One liner to generate truly random passwords from command line
Yimin Rong wrote: wget -q -O - "http://random.org/integers/? num=8&min=33&max=126&col=8&base=16&format=plain&rnd=new" | perl -ne 'foreach (split(/\t/, $_)) {print chr(hex($_));} print "\n"' You can simplify the perl part to: perl -lane'print map chr hex, @F' Or just using perl: perl -MLWP::Simple -le'print map chr hex, split " ", get "http://random.org/integers/?num=8&min=33&max=126&col=8&base=16&format=plain&rnd=new";' And if you're not connected to the Net: perl -le'@chars = 33 .. 126; print map chr $chars[ rand @chars ], 1 .. 8' John -- Perl isn't a toolbox, but a small machine shop where you can special-order certain sorts of tools at low cost and in short order.-- Larry Wall -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
One liner to generate truly random passwords from command line
wget -q -O - "http://random.org/integers/? num=8&min=33&max=126&col=8&base=16&format=plain&rnd=new" | perl -ne 'foreach (split(/\t/, $_)) {print chr(hex($_));} print "\n"' wget reads web pages random.org generates random numbers using atmospheric noise perl splits the input into tokens and converts /YR -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Unix command-line tools to edit SharePoint site?
And here is the createEnvelope function: # # Functions listed below are internal to the creation of the custom SOAP requests. # sub createEnvelope { my $action = shift; my $namesp = shift; my $params = shift; my $soap = ' http://www.w3.org/2001/ XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"; xmlns:soap="http://www.w3.org/2003/05/soap-envelope";> '; $soap .= '<' . $action . ' xmlns="' . $namesp . '">'; $soap .= parseParams($params); $soap .= ''; return $soap; } # end createEnvelope() sub parseParams { my $params = shift; my $plist = ''; while (my ($key, $value) = each(%{$params})) { $plist .= '<' . $key . '>' . $value . ''; } return $plist; } # end parseParams() -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Unix command-line tools to edit SharePoint site?
Jack Trinh (jtrinh) wrote: > > SE CORRECT THEM FOR ME. > Thanks > JACK Hush -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Unix command-line tools to edit SharePoint site?
SE CORRECT THEM FOR ME. Thanks JACK -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] Sent: Friday, June 13, 2008 05:15 PM Pacific Standard Time To: beginners@perl.org Subject:Re: Unix command-line tools to edit SharePoint site? Kelley, I just completed a project had to figure out how to create SharePoint calendar events from Perl. This was quite a chore, as MS's SOAP interface does not adhere to open standards. As such, I had to create my own custom SOAP requests that contained MS's CAML query language. See the example below, and feel free to contact me, ericjhahn [at] gmail [dot] com, if you have any other problems / questions. # the GUID can be accessed from the GetListCollection and looks like 082CAB40-1E09-40F1-918C-29563AE9D135 use Data::Dumper; # this is an excellent utility for printing hashes etc. use LWP::UserAgent; use HTTP::Request; use strict; # CREATE EVENT my $site = '/sites/'; my %fields = ( Title => 'My New Event', Location => 'The Warehouse', Description => 'Stock some stuff', EventDate => '2008-06-13 09:45:45', EndDate => '2008-06-13 10:15:45', ); my $eventID = createCalendarEvent($guid, $site, \%fields); sub createCalendarEvent { my $listGUID = shift; my $site = shift; my $fields = shift; my $batch = ' '; while (my ($key, $value) = each (%{$fields})) { $batch .= '' . $value . ''; } $batch .= ' '; my %parameters = ("listName" => $listGUID, # calendar list "updates" => $batch ); my $soap = createEnvelope("UpdateListItems", "http://schemas.microsoft.com/sharepoint/ soap/", \%parameters ); my $ua = new LWP::UserAgent(keep_alive => 1); # the only authentication i could get to work was through the URL (we have basic auth on the sharepoint site) my $request = new HTTP::Request(POST => 'http://:@' . $site . '/_vti_bin/Lists.asmx'); $request->content_type("text/xml; charset=utf-8"); $request->content($soap); $request->header(SOAPAction => '"http://schemas.microsoft.com/ sharepoint/soap/UpdateListItems"'); my $response = $ua->request($request); # parsing to return the event ID so that we can store it and access this event later if($response->code == 200) { my $id = $response->as_string; $id = substr($id, index($id, "ows_ID")); $id =~ s/^.*ows_ID="//; $id =~ s/".*$//; chomp($id); return $id; } else { return 0; } } # end createCalendarEvent() -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Unix command-line tools to edit SharePoint site?
Kelley, I just completed a project had to figure out how to create SharePoint calendar events from Perl. This was quite a chore, as MS's SOAP interface does not adhere to open standards. As such, I had to create my own custom SOAP requests that contained MS's CAML query language. See the example below, and feel free to contact me, ericjhahn [at] gmail [dot] com, if you have any other problems / questions. # the GUID can be accessed from the GetListCollection and looks like 082CAB40-1E09-40F1-918C-29563AE9D135 use Data::Dumper; # this is an excellent utility for printing hashes etc. use LWP::UserAgent; use HTTP::Request; use strict; # CREATE EVENT my $site = '/sites/'; my %fields = ( Title => 'My New Event', Location => 'The Warehouse', Description => 'Stock some stuff', EventDate => '2008-06-13 09:45:45', EndDate => '2008-06-13 10:15:45', ); my $eventID = createCalendarEvent($guid, $site, \%fields); sub createCalendarEvent { my $listGUID = shift; my $site = shift; my $fields = shift; my $batch = ' '; while (my ($key, $value) = each (%{$fields})) { $batch .= '' . $value . ''; } $batch .= ' '; my %parameters = ("listName" => $listGUID, # calendar list "updates" => $batch ); my $soap = createEnvelope("UpdateListItems", "http://schemas.microsoft.com/sharepoint/ soap/", \%parameters ); my $ua = new LWP::UserAgent(keep_alive => 1); # the only authentication i could get to work was through the URL (we have basic auth on the sharepoint site) my $request = new HTTP::Request(POST => 'http://:@' . $site . '/_vti_bin/Lists.asmx'); $request->content_type("text/xml; charset=utf-8"); $request->content($soap); $request->header(SOAPAction => '"http://schemas.microsoft.com/ sharepoint/soap/UpdateListItems"'); my $response = $ua->request($request); # parsing to return the event ID so that we can store it and access this event later if($response->code == 200) { my $id = $response->as_string; $id = substr($id, index($id, "ows_ID")); $id =~ s/^.*ows_ID="//; $id =~ s/".*$//; chomp($id); return $id; } else { return 0; } } # end createCalendarEvent() -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Unix command-line tools to edit SharePoint site?
I begrudgingly use a Windows SharePoint server at a customer's request. I'd like to automate (command-line) updating and creating documents, lists, etc. Is there a Unix tool that does this? I know SharePoint has an "API", which basically spoofs the GET/POST calls that your browser would make(?). Has anyone written a Unix command-line tool (or Perl module, etc) that abstracts this? -- We're just a Bunch Of Regular Guys, a collective group that's trying to understand and assimilate technology. We feel that resistance to new ideas and technology is unwise and ultimately futile. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to command line perl mail client for Microsoft exhange?
On Thu, Apr 24, 2008 at 12:07 AM, Siegfried Heintze (Aditi) <[EMAIL PROTECTED]> wrote: > I started installing Mail::Sender, Mail::Send and Mail::Util and discovered > it is prompting me for a default SMTP server as part of the installation > server. Well I go to outlook and view my account settings and discover that > I'm connect to an exchange server. Is that what I specify for my SMTP server? IIRC, Exchange acts like an ESMTP server when contacted on the normal SMTP port. You can test this by telneting to the Exchage server on port 25 (telnet exchangeservername 25 in cmd.exe). You can also try just putting the name of the Exchange server in where it expects the SMTP server. You may need to configure the Exchange server to allow this feature. -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
How to command line perl mail client for Microsoft exhange?
I started installing Mail::Sender, Mail::Send and Mail::Util and discovered it is prompting me for a default SMTP server as part of the installation server. Well I go to outlook and view my account settings and discover that I'm connect to an exchange server. Is that what I specify for my SMTP server? Thanks, Siegfried
Re: Using perl variable in command line
On Thu, Feb 21, 2008 at 10:35 AM, Yoyoyo Yoyoyoyo <[EMAIL PROTECTED]> wrote: > But the commands do still run in the command line, is there anyway to throw > a perl variable in there? Yes. You did it correctly. Look at the code I posted. > my $y = `echo $x`; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Using perl variable in command line
But the commands do still run in the command line, is there anyway to throw a perl variable in there? yitzle <[EMAIL PROTECTED]> wrote: Perl captures the output from backticks so nothing gets printed to the screen. __CODE__ my $x = "efg"; my $y = `echo $x`; print $y; __OUTPUT__ efg __END__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ - Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now.
Re: Using perl variable in command line
Perl captures the output from backticks so nothing gets printed to the screen. __CODE__ my $x = "efg"; my $y = `echo $x`; print $y; __OUTPUT__ efg __END__ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Using perl variable in command line
Hi all, I am having trouble representing a perl variable when using back ticks to run commands from the unix command line. A simple example would be: #!usr/bin/perl $X = $ARGV[0]; `echo $X`; This does not work (neither does `echo \$X`;). Is there anyway to represent a perl variable when using the backticks? Any help is appreciated, thanks. - Looking for last minute shopping deals? Find them fast with Yahoo! Search.
Re: order of command line switch?
On Feb 13, 2008 2:57 PM, ciwei <[EMAIL PROTECTED]> wrote: snip > so why the order of -n -e switch make the differience? > this is perl 5.8.4. > Thanks snip This is true in all versions of Perl. It is becuase you are allowed to have more than one -e option: perl -e 'print "read ";' -e 'print "the ";' -e 'print "fine ";' -e 'print "manual\n";' If you look at the syntax in perlrun* you will see that -e must be followed by a string. The letter n is being used as the string, so you program looks like this: #!/usr/bin/perl n and it is being passed "print if /SUNW/" in $ARGV[0]. A constant is a valid Perl program (n is a bareword, so it is being treated as "n" by the parser), but it doesn't do anything. You can see this more clearly by turning off barewords with the strict** pragma: perl -Mstrict -en 'print if /SUNW/' Bareword "n" not allowed while "strict subs" in use at -e line 1. Execution of -e aborted due to compilation errors. * perldoc perlrun or http://perldoc.perl.org/perlrun.html#SYNOPSIS ** perldoc strict or http://perldoc.perl.org/strict.html -- Chas. Owens wonkden.net The most important skill a programmer can have is the ability to read. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: order of command line switch?
On Feb 13, 2008 11:57 AM, ciwei <[EMAIL PROTECTED]> wrote: > hostA>ls > SUNWjassVRTSVRTSicsco VRTSvcs > emc SUNWmlibVRTSalloc VRTSjre VRTSvlicVRTSvxvm > > hostA>ls | perl -en 'print if /SUNW/' > > return nothing , while > > hostA>ls | perl -ne 'print if /SUNW/' > SUNWits > SUNWjass > SUNWmlib > SUNWrtvc > > so why the order of -n -e switch make the differience? > this is perl 5.8.4. > Thanks > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > I think the code between single quotes is like a parameter to -e switch so it has to be -ne 'code' instead of -en 'code' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
order of command line switch?
hostA>ls SUNWjassVRTSVRTSicsco VRTSvcs emc SUNWmlibVRTSalloc VRTSjre VRTSvlicVRTSvxvm hostA>ls | perl -en 'print if /SUNW/' return nothing , while hostA>ls | perl -ne 'print if /SUNW/' SUNWits SUNWjass SUNWmlib SUNWrtvc so why the order of -n -e switch make the differience? this is perl 5.8.4. Thanks -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line installing perl modules
On Thursday 31 January 2008 20:40:13 Chas. Owens wrote: > > How do I automate the install of a bunch of modules. Is it enough to just > > install the tarballs, or will there be dependencies that I have to trace > > down first? If so what is the best way to do that? > You automate it by using the CPAN module or the cpan command. That is > what they do. There will undoubtly be dependencies and you will have > to chase them down yourself; usually after the perl Makefile.PL step > fails. Those installs will be done from disk, not the Internet. So are those messages listed as warnings right after where it usually says all OK? -- Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line installing perl modules
On Jan 31, 2008 8:32 PM, Bobby <[EMAIL PROTECTED]> wrote: snip > Yes, thank you, but that part is old hat. What I'm looking for is if anything > is different when I simply install the tarballs? snip You have to do everything yourself. snip > How do I automate the install of a bunch of modules. Is it enough to just > install the tarballs, or will there be dependencies that I have to trace down > first? If so what is the best way to do that? snip You automate it by using the CPAN module or the cpan command. That is what they do. There will undoubtly be dependencies and you will have to chase them down yourself; usually after the perl Makefile.PL step fails. snip > I did notice during install that it said something like All OK. Then on one it > gave a warning saying that some other module was needed. snip If you are not using cpan then you need to pay very close attention to all messages given to you by the install process. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line installing perl modules
On Thursday 31 January 2008 20:15:22 Chas. Owens wrote: > On Jan 31, 2008 7:44 PM, Bobby <[EMAIL PROTECTED]> wrote: > > On Thursday 31 January 2008 17:45:53 Chas. Owens wrote: > > > On Jan 31, 2008 3:01 PM, Bobby <[EMAIL PROTECTED]> wrote: > > > snip > > > > > > > This will be done only on brand new Slackware 12 installs which does > > > > not have CPAN. > > > > > > snip > > > > > > That doesn't sound right. Are you certain you have Perl installed? > > > CPAN is part of Core Perl and should be there if Perl is installed. > > > Try > > > > Sorry, yes that part is installed. What I meant is it does not have the > > .cpan directory and as such has not been initialized to use the online > > repository. > > snip > > That directory is created by running cpan or perl -MCPAN -e shell. > Just run it, accept the defaults, and choose some repositories. Yes, thank you, but that part is old hat. What I'm looking for is if anything is different when I simply install the tarballs? How do I automate the install of a bunch of modules. Is it enough to just install the tarballs, or will there be dependencies that I have to trace down first? If so what is the best way to do that? I did notice during install that it said something like All OK. Then on one it gave a warning saying that some other module was needed. -- Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line installing perl modules
On Jan 31, 2008 7:44 PM, Bobby <[EMAIL PROTECTED]> wrote: > On Thursday 31 January 2008 17:45:53 Chas. Owens wrote: > > On Jan 31, 2008 3:01 PM, Bobby <[EMAIL PROTECTED]> wrote: > > snip > > > > > This will be done only on brand new Slackware 12 installs which does not > > > have CPAN. > > > > snip > > > > That doesn't sound right. Are you certain you have Perl installed? > > CPAN is part of Core Perl and should be there if Perl is installed. > > Try > > Sorry, yes that part is installed. What I meant is it does not have the .cpan > directory and as such has not been initialized to use the online repository. snip That directory is created by running cpan or perl -MCPAN -e shell. Just run it, accept the defaults, and choose some repositories. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line installing perl modules
On Thursday 31 January 2008 17:45:53 Chas. Owens wrote: > On Jan 31, 2008 3:01 PM, Bobby <[EMAIL PROTECTED]> wrote: > snip > > > This will be done only on brand new Slackware 12 installs which does not > > have CPAN. > > snip > > That doesn't sound right. Are you certain you have Perl installed? > CPAN is part of Core Perl and should be there if Perl is installed. > Try Sorry, yes that part is installed. What I meant is it does not have the .cpan directory and as such has not been initialized to use the online repository. -- Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line installing perl modules
On Jan 31, 2008 3:01 PM, Bobby <[EMAIL PROTECTED]> wrote: snip > This will be done only on brand new Slackware 12 installs which does not have > CPAN. snip That doesn't sound right. Are you certain you have Perl installed? CPAN is part of Core Perl and should be there if Perl is installed. Try perl -MCPAN -e shell or cpan If those don't work then you most likely don't have Perl installed (I just check the package http://packages.slackware.it/package.php?q=current/perl-5.8.8-i486-4 and it does in fact have the cpan command and the CPAN module). If you really don't have CPAN, well, your system is hosed and it is unlikely that the following will work, but it is how you install modules by hand: tar xvfz modulename.tgz cd modulename perl Makefile.PL make make test make install Stop if you get an error at any step. If you are installing in a different directory than the default you can pass PREFIX=/path/to/install to perl Makefile.PL. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Command line installing perl modules
Hi, I'm trying to figure out how to install perl modules from command line (to automate the install process). CPAN allowed me to d/l direct which results in tarballs. Are there any caveats to watch out for when installing them this way? This will be done only on brand new Slackware 12 installs which does not have CPAN. I was thinking of copying .cpan but it's probably not even needed, and might introduce incompatibility issues. The important part is to get a cookie cutter system that can be done over and over. -- Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cpan command line
On Sep 28, 12:32 pm, [EMAIL PROTECTED] (Bobby) wrote: > On Friday 28 September 2007 12:26:08 Paul Lalli wrote: > > > [EMAIL PROTECTED] (Bobby) wrote: > > > > > What is the command to tell cpan to accept the default/suggested > > > > > values? > > When you run the cpan set up command, it will ask you if you're "ready > > for manual configuration". Say no. That will cause it to use the > > default values. > Thanks, though I'm not sure we are talking about the same thing. You're right, we weren't. :-) > When installing modules it sometimes ask if you want additional modules as > well. At that point I need it not to ask that but just go ahead and do what > it thinks is best. Start up your cpan shell, and type: o conf prerequisites_policy follow o conf commit That will tell cpan to go ahead and just download whatever modules it needs in order to install the module you're trying to install. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cpan command line
On Friday 28 September 2007 12:26:08 Paul Lalli wrote: > On Sep 28, 9:26 am, [EMAIL PROTECTED] (Bobby) wrote: > > On Friday 28 September 2007 06:01:31 Srinivas wrote: > > > just hit "Enter" > > > > > > -srini > > > > > > Bobby wrote: > > > > Hi, > > > > > > > > What is the command to tell cpan to accept the default/suggested > > > > values? > > > > No. Command line option so you don't have to be there and press Enter. > > When you run the cpan set up command, it will ask you if you're "ready > for manual configuration". Say no. That will cause it to use the > default values. > > Paul Lalli Thanks, though I'm not sure we are talking about the same thing. When installing modules it sometimes ask if you want additional modules as well. At that point I need it not to ask that but just go ahead and do what it thinks is best. -- Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cpan command line
On Sep 28, 9:26 am, [EMAIL PROTECTED] (Bobby) wrote: > On Friday 28 September 2007 06:01:31 Srinivas wrote: > > > just hit "Enter" > > > -srini > > > Bobby wrote: > > > Hi, > > > > What is the command to tell cpan to accept the default/suggested values? > > No. Command line option so you don't have to be there and press Enter. When you run the cpan set up command, it will ask you if you're "ready for manual configuration". Say no. That will cause it to use the default values. Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cpan command line
On Friday 28 September 2007 06:01:31 Srinivas wrote: > just hit "Enter" > > -srini > > Bobby wrote: > > Hi, > > > > What is the command to tell cpan to accept the default/suggested values? No. Command line option so you don't have to be there and press Enter. -- Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: cpan command line
just hit "Enter" -srini Bobby wrote: Hi, What is the command to tell cpan to accept the default/suggested values? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
cpan command line
Hi, What is the command to tell cpan to accept the default/suggested values? -- Bobby -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: running cgi off the command line works, but running on the browser fails with a 500 error
On Sep 27, 11:59 am, [EMAIL PROTECTED] (Pat Rice) wrote: > Hi all > Error 500 error is the follwoing > > [Thu Sep 27 16:26:56 2007] [error] [client 10.16.153.99] Prototype mismatch: > sub main::head: none vs ($) at /var/www/cgi-bin/srHandler4.cgi line 7 > [Thu Sep 27 16:26:57 2007] [error] [client 10.16.153.99] [Thu Sep 27 > 16:26:57 2007] srHandler4.cgi: Error 500 > onhttp://pseweb.vmware.com/pending/194951021 > a > t /var/www/cgi-bin/srHandler4.cgi line 25. > > The problem is with line 7 and 25 > > line 7 -- shown below is prety simple > 5 adding the bits from teat.pl > 6 use warnings; > 7 use LWP::Simple; > > Line 25 -- shown below, is just a simple getstore, this works when run from > the command line, but when run form the webserver, I get above error > message, I've tried the usual 500 error messages, just wondering if anyone > has any ideas ??? Always read the documentation for the modules you're using. http://search.cpan.org/~gaas/libwww-perl-5.808/lib/LWP/Simple.pm#CAVEAT Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: running cgi off the command line works, but running on the browser fails with a 500 error
On 9/27/07, Pat Rice <[EMAIL PROTECTED]> wrote: > Line 25 -- shown below, is just a simple getstore, this works when run from > the command line, but when run form the webserver, I get above error > message, I've tried the usual 500 error messages, just wondering if anyone > has any ideas ??? A "500 error message" is pretty nearly useless; what you want is the dying words from your program, which are probably in your server's error log. But I'd guess from the nature of your problem that you might have a different version of Perl on the webserver than you used for testing on the command line. Or, you didn't use the -w switch when you tested your program on the command line. > 1 #!/usr/bin/perl -w > 2 use CGI qw(:standard); > 3 use CGI::Carp qw(warningsToBrowser fatalsToBrowser); > 4 use strict; > 5 adding the bits from teat.pl > 6 use warnings; > 7 use LWP::Simple; I suspect that LWP::Simple is trying to import a subroutine named head(), but you already got one from the CGI module. If that's the case, you can tell either one of the modules that you don't want it to import head(), and that should solve your problem. Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
running cgi off the command line works, but running on the browser fails with a 500 error
Hi all Error 500 error is the follwoing [Thu Sep 27 16:26:56 2007] [error] [client 10.16.153.99] Prototype mismatch: sub main::head: none vs ($) at /var/www/cgi-bin/srHandler4.cgi line 7 [Thu Sep 27 16:26:57 2007] [error] [client 10.16.153.99] [Thu Sep 27 16:26:57 2007] srHandler4.cgi: Error 500 on http://pseweb.vmware.com/pending/194951021 a t /var/www/cgi-bin/srHandler4.cgi line 25. The problem is with line 7 and 25 line 7 -- shown below is prety simple 5 adding the bits from teat.pl 6 use warnings; 7 use LWP::Simple; Line 25 -- shown below, is just a simple getstore, this works when run from the command line, but when run form the webserver, I get above error message, I've tried the usual 500 error messages, just wondering if anyone has any ideas ??? 21 my $url = "http://private.private.com/pending/$variable_name";; 22 #print "\n This is the web site that I'm trying to got to : $url"; 23 my $file = 'testPseweb2.html'; 24 my $status = getstore($url, $file); 25 die "Error $status on $url" unless is_success($status); 26 I've been stuck on this for a while and I'm starting to wonder. I'm attaching script below 1 #!/usr/bin/perl -w 2 use CGI qw(:standard); 3 use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 4 use strict; 5 adding the bits from teat.pl 6 use warnings; 7 use LWP::Simple; 8 9 ## setting up the variables for the form 10 my $query; 11 my $p; # chaged this for trouble shooting 12 #my $variable_name = param("srNumber"); 13 my $variable_name = 194951021; 14 15 16 17 ### adding teat.pl 18 #here I take the number form the form and try to pull down page 19 # This fails with 500 error, but testing it through a browser it works, 20 # Hence the resion for the print statment 21 my $url = "http://test.test.com/pending/$variable_name";; 22 #print "\n This is the web site that I'm trying to got to : $url"; 23 my $file = 'testPseweb2.html'; 24 my $status = getstore($url, $file); 25 die "Error $status on $url" unless is_success($status); 26 27 28 29 30 31 ### this part parses the file pulled down from lwp, and pick out what I want 32 my $img; 33 my $src; 34 my $alt; 35 my $a; 36 my $href; 37 my $href2; 38 my $msup; 39 my $msupdir; 40 my $substrMsup; 41 42 43 open(IN, "<$file") || die "Can't open $file: $!"; 44 while () { 45 my @array_of_data = ; 46 47 foreach my $line (@array_of_data) 48 { 49 50 chomp($line); 51 52 if ($line =~ /vm-support/i) 53 { 54 55 Now do something in this if statment 56 Split The file, and pick out the correct word for time and date. 57 ##I'm picking out what I want out of the web page here 58 ($img, $src, $alt, $a, $href) = split (' ', $line); 59 ($href2, $msup, $msupdir) = split ('"', $href); 60 ($substrMsup) = split ('/', $msup); 61 } 62 } 63 } 64 close(IN); 65 66 print header; 67 print start_html("Thank You"); 68 print h2("Thank You"); 69 70 #print "variable name: $variable_name"; 71 #print "vm-support: $substrMsup"; 72 print end_html; 73 74 75 76
Re: Command line usage [solved]
On Jun 18, 5:54 pm, [EMAIL PROTECTED] (John Degen) wrote: > >- Original Message > >From: Paul Lalli <[EMAIL PROTECTED]> > >To: [EMAIL PROTECTED] > >Sent: Monday, June 18, 2007 6:47:05 PM > >Subject: Re: Command line usage > > >On Jun 18, 10:50 am, [EMAIL PROTECTED] (John Degen) wrote: > > >> I think I'm out of luck with this OS;) Your suggestion for creating a > >> backup > >> file gave the same result: no error, no change in the files. The output of > >> 'perl -le"print for @ARGV" *' is * and the other is *.*. Funny though that > >> sed *does* work. > > >Ah. Well there's your problem. The command line interpreter you're > >running doesn't expand wildcards. That's why Perl wasn't giving you > >any errors - it had nothing to do because there was no file named "*" > >that it could find... You'll have to expand the wildcard from within > >Perl. > > >perl -pi.bkp -e"BEGIN { @ARGV = glob($ARGV[0]); } s/old/new/;" * > > >Hope this helps, > >Paul Lalli > > Thank you all for your responses. Paul's suggestion above is the winner. The > command works, creates a neat backup file and does what it's told. I'll be > checking the docs to see *why* it works:) Normally your command line interpreter would expand "*" into a list of files, and perl would store them in @ARGV, e.g., $ARGV[0] = "a.txt"; $ARGV[1] = "b.txt"; $ARGV[2] = "c.txt"; Instead, yours is not expanding, but simply passing "*" unchanged, but perl still stores it in @ARGV, which looks like $ARGV[0] = "*"; So in the BEGIN block (which executes before the -p flag starts reading files), Paul's code passes $ARGV[0] to the glob() function, which is perl's way of expanding "*" into a list of files. Assigning that output to @ARGV (overwriting $ARGV[0] in the process) yields, e.g., $ARGV[0] = "a.txt"; $ARGV[1] = "b.txt"; $ARGV[2] = "c.txt"; Q.E.F. -- Brad -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line usage
##I have files read into $output_dir if ($output_dir =~ "_Modified") { $allfile2 = $output_dir; #set allfile2 equal to output_dir to keep output_dir untouched $_ = $allfile2; #set input string equal to allfile2 for replacement s/_Modified//; #replace _Modified with nothing anywhere it appears in the string #$_ now equals the filename without the "_Modified" $allfile2 = $_; #set allfile2 equal to $_ rename ($output_dir, $allfile2);#rename the "_Modified" files with the new filenames #warn $allfile2;#shows what allfile2 currently contains } Hope this helps! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: [Perl 5.8.8 on WinXP] Command line usage
Rob Dixon schreef: > perl -e "print qq($_\n) foreach <*>" which as good as identical to perl -wle "print for <*>" -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line usage [solved]
> > >- Original Message >From: Paul Lalli <[EMAIL PROTECTED]> >To: beginners@perl.org >Sent: Monday, June 18, 2007 6:47:05 PM >Subject: Re: Command line usage > >On Jun 18, 10:50 am, [EMAIL PROTECTED] (John Degen) wrote: > >> I think I'm out of luck with this OS;) Your suggestion for creating a backup >> file gave the same result: no error, no change in the files. The output of >> 'perl -le"print for @ARGV" *' is * and the other is *.*. Funny though that >> sed *does* work. > >Ah. Well there's your problem. The command line interpreter you're >running doesn't expand wildcards. That's why Perl wasn't giving you >any errors - it had nothing to do because there was no file named "*" >that it could find... You'll have to expand the wildcard from within >Perl. > >perl -pi.bkp -e"BEGIN { @ARGV = glob($ARGV[0]); } s/old/new/;" * > >Hope this helps, >Paul Lalli Thank you all for your responses. Paul's suggestion above is the winner. The command works, creates a neat backup file and does what it's told. I'll be checking the docs to see *why* it works:) Best regards, John Degen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Get your own web address. Have a HUGE year through Yahoo! Small Business. http://smallbusiness.yahoo.com/domains/?p=BESTDEAL -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line usage
On Jun 18, 10:50 am, [EMAIL PROTECTED] (John Degen) wrote: > I think I'm out of luck with this OS;) Your suggestion for creating a backup > file gave the same result: no error, no change in the files. The output of > 'perl -le"print for @ARGV" *' is * and the other is *.*. Funny though that > sed *does* work. Ah. Well there's your problem. The command line interpreter you're running doesn't expand wildcards. That's why Perl wasn't giving you any errors - it had nothing to do because there was no file named "*" that it could find... You'll have to expand the wildcard from within Perl. perl -pi.bkp -e"BEGIN { @ARGV = glob($ARGV[0]); } s/old/new/;" * Hope this helps, Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: [Perl 5.8.8 on WinXP] Command line usage
Octavian Rasnita wrote: Rob Dixon wrote: John Degen wrote: I'm using Perl 5.8.8 from ActiveState on Windows XP. I'm trying to accomplish a search and replace in a number of files in the same directory from the command line (cmd.exe). The problem is that the command perl -i -e "s/old/new/" * fails silently, i.e. no changes take place. My question is: does * indicate all files in the current directory (this did work in the Windows version of sed I tried)? I cannot find this in the docs or using Google. Or am I making another mistake? Hi John Three problems here that I can see: - Perl won't do an in-place edit successfully on a Windows system. You have to specify a name for the old file to be renamed to. - It is the command shell on Unix systems that expands the wildcard into a list of filenames. On Windows your program sees just the single argument '*'. - You have written no code to process the arguments passed. You program is simply s/old/new/ which will just try to replace 'old' with 'new' in an uninitialised $_ variable (try perl -w -i -e "s/old/new/" * to see the evidence). I suggest you use something like perl -w -i.bak -p -e "s/old/new/" but I haven't tested this as you already have a directory set up ready to try it on :) A program in command line that works might be too long under Windows, but if it is necessary it could be made sending the list of files to the program with a pipe, like: dir /b | perl -e "print ;" This command prints the list of filenames on the console, and the dos command dir accepts wildcards, then the perl program could do anything with those files, like opening them, modifying (Please bottom-post your replies so that extended threads remain comprehensible. Thank you.) That is unnecessary. Just perl -e "print qq($_\n) foreach <*>" will do the same thing. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: [Perl 5.8.8 on WinXP] Command line usage
A program in command line that works might be too long under Windows, but if it is necessary it could be made sending the list of files to the program with a pipe, like: dir /b | perl -e "print ;" This command prints the list of filenames on the console, and the dos command dir accepts wildcards, then the perl program could do anything with those files, like opening them, modifying Octavian - Original Message - From: "Rob Dixon" <[EMAIL PROTECTED]> To: Cc: "John Degen" <[EMAIL PROTECTED]> Sent: Monday, June 18, 2007 5:48 PM Subject: Re: [Perl 5.8.8 on WinXP] Command line usage John Degen wrote: I'm using Perl 5.8.8 from ActiveState on Windows XP. I'm trying to accomplish a search and replace in a number of files in the same directory from the command line (cmd.exe). The problem is that the command perl -i -e "s/old/new/" * fails silently, i.e. no changes take place. My question is: does * indicate all files in the current directory (this did work in the Windows version of sed I tried)? I cannot find this in the docs or using Google. Or am I making another mistake? Hi John Three problems here that I can see: - Perl won't do an in-place edit successfully on a Windows system. You have to specify a name for the old file to be renamed to. - It is the command shell on Unix systems that expands the wildcard into a list of filenames. On Windows your program sees just the single argument '*'. - You have written no code to process the arguments passed. You program is simply s/old/new/ which will just try to replace 'old' with 'new' in an uninitialised $_ variable (try perl -w -i -e "s/old/new/" * to see the evidence). I suggest you use something like perl -w -i.bak -p -e "s/old/new/" but I haven't tested this as you already have a directory set up ready to try it on :) HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line usage
-- Sane sicut lux seipsam, & tenebras manifestat, sic veritas norma sui, & falsi est. -- Spinoza > > >- Original Message >From: Paul Lalli <[EMAIL PROTECTED]> >To: beginners@perl.org >Sent: Monday, June 18, 2007 3:56:04 PM >Subject: Re: Command line usage > >On Jun 18, 8:40 am, [EMAIL PROTECTED] (John Degen) wrote: >> Thanks for your speedy reply Bob. I tried your suggestion, but the same >> outcome: the command fails without any complaints. BTW, the files didn't >> have extensions. They are three test files (plain text) containing >> respectively "love, live and luve". The actual command that I tried was perl >> -i -e "s/ve/ver/" *.* >> Any other ideas I might try? > >Windows has never let me replace files inline - that is, you can't not >give an extension for the -i option. You have to provide it with an >extension so that the original files are saved as backups. (However, >it's always given me an error when I've tried - not sure why you're >not getting one). > >try: >perl -i.bkp -e"s/ve/ver/" *.* > >You can also run a quick test to determine what * and *.* mean in >Windows by something like this: > >perl -le"print for @ARGV" * >perl -le"print for @ARGV" *.* > >Paul Lalli Thanks Paul, I think I'm out of luck with this OS;) Your suggestion for creating a backup file gave the same result: no error, no change in the files. The output of 'perl -le"print for @ARGV" *' is * and the other is *.*. Funny though that sed *does* work. Best regards, John Degen -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. http://mobile.yahoo.com/go?refer=1GNXIC -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: [Perl 5.8.8 on WinXP] Command line usage
John Degen wrote: I'm using Perl 5.8.8 from ActiveState on Windows XP. I'm trying to accomplish a search and replace in a number of files in the same directory from the command line (cmd.exe). The problem is that the command perl -i -e "s/old/new/" * fails silently, i.e. no changes take place. My question is: does * indicate all files in the current directory (this did work in the Windows version of sed I tried)? I cannot find this in the docs or using Google. Or am I making another mistake? Hi John Three problems here that I can see: - Perl won't do an in-place edit successfully on a Windows system. You have to specify a name for the old file to be renamed to. - It is the command shell on Unix systems that expands the wildcard into a list of filenames. On Windows your program sees just the single argument '*'. - You have written no code to process the arguments passed. You program is simply s/old/new/ which will just try to replace 'old' with 'new' in an uninitialised $_ variable (try perl -w -i -e "s/old/new/" * to see the evidence). I suggest you use something like perl -w -i.bak -p -e "s/old/new/" but I haven't tested this as you already have a directory set up ready to try it on :) HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Command line usage
On Jun 18, 8:40 am, [EMAIL PROTECTED] (John Degen) wrote: > Thanks for your speedy reply Bob. I tried your suggestion, but the same > outcome: the command fails without any complaints. BTW, the files didn't have > extensions. They are three test files (plain text) containing respectively > "love, live and luve". The actual command that I tried was perl -i -e > "s/ve/ver/" *.* > Any other ideas I might try? Windows has never let me replace files inline - that is, you can't not give an extension for the -i option. You have to provide it with an extension so that the original files are saved as backups. (However, it's always given me an error when I've tried - not sure why you're not getting one). try: perl -i.bkp -e"s/ve/ver/" *.* You can also run a quick test to determine what * and *.* mean in Windows by something like this: perl -le"print for @ARGV" * perl -le"print for @ARGV" *.* Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: [Perl 5.8.8 on WinXP] Command line usage
Thanks for your speedy reply Bob. I tried your suggestion, but the same outcome: the command fails without any complaints. BTW, the files didn't have extensions. They are three test files (plain text) containing respectively "love, live and luve". The actual command that I tried was perl -i -e "s/ve/ver/" *.* Any other ideas I might try? Regards, John - Original Message From: Bob McConnell <[EMAIL PROTECTED]> To: John Degen <[EMAIL PROTECTED]>; beginners@perl.org Sent: Monday, June 18, 2007 2:31:00 PM Subject: RE: [Perl 5.8.8 on WinXP] Command line usage Windows uses file extensions for a variety of reasons, so it expects the period in file names. In most cases, the file spec "*" will only return files with no extension, such as "README". Have you tried "*.*" instead? Bob McConnell > -Original Message- > From: John Degen [mailto:[EMAIL PROTECTED] > Sent: Monday, June 18, 2007 8:26 AM > To: beginners@perl.org > Subject: [Perl 5.8.8 on WinXP] Command line usage > > Hello, > > I'm using Perl 5.8.8 from ActiveState on Windows XP. I'm > trying to accomplish a search and replace in a number of > files in the same directory from the command line (cmd.exe). > The problem is that the command perl -i -e "s/old/new/" * > fails silently, i.e. no changes take place. My question is: > does * indicate all files in the current directory (this did > work in the Windows version of sed I tried)? I cannot find > this in the docs or using Google. Or am I making another mistake? > > Thank you for your time. > > John Degen > > -- > Sane sicut lux seipsam, & tenebras manifestat, sic veritas > norma sui, & falsi est. -- Spinoza > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/ Take the Internet to Go: Yahoo!Go puts the Internet in your pocket: mail, news, photos & more. http://mobile.yahoo.com/go?refer=1GNXIC -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: [Perl 5.8.8 on WinXP] Command line usage
Windows uses file extensions for a variety of reasons, so it expects the period in file names. In most cases, the file spec "*" will only return files with no extension, such as "README". Have you tried "*.*" instead? Bob McConnell > -Original Message- > From: John Degen [mailto:[EMAIL PROTECTED] > Sent: Monday, June 18, 2007 8:26 AM > To: beginners@perl.org > Subject: [Perl 5.8.8 on WinXP] Command line usage > > Hello, > > I'm using Perl 5.8.8 from ActiveState on Windows XP. I'm > trying to accomplish a search and replace in a number of > files in the same directory from the command line (cmd.exe). > The problem is that the command perl -i -e "s/old/new/" * > fails silently, i.e. no changes take place. My question is: > does * indicate all files in the current directory (this did > work in the Windows version of sed I tried)? I cannot find > this in the docs or using Google. Or am I making another mistake? > > Thank you for your time. > > John Degen > > -- > Sane sicut lux seipsam, & tenebras manifestat, sic veritas > norma sui, & falsi est. -- Spinoza > > > > > > __ > __ > Get your own web address. > Have a HUGE year through Yahoo! Small Business. > http://smallbusiness.yahoo.com/domains/?p=BESTDEAL > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
[Perl 5.8.8 on WinXP] Command line usage
Hello, I'm using Perl 5.8.8 from ActiveState on Windows XP. I'm trying to accomplish a search and replace in a number of files in the same directory from the command line (cmd.exe). The problem is that the command perl -i -e "s/old/new/" * fails silently, i.e. no changes take place. My question is: does * indicate all files in the current directory (this did work in the Windows version of sed I tried)? I cannot find this in the docs or using Google. Or am I making another mistake? Thank you for your time. John Degen -- Sane sicut lux seipsam, & tenebras manifestat, sic veritas norma sui, & falsi est. -- Spinoza Get your own web address. Have a HUGE year through Yahoo! Small Business. http://smallbusiness.yahoo.com/domains/?p=BESTDEAL -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Detecting whether a script was called via CGI or the command line
On May 4, 2007, at 2:44 PM, Nigel Peck wrote: Within the script I want to know where it was executed from; CGI or command line/cron job. I'm currently checking @ARGV to do this i.e. if there is data in @ARGV then it was called from the command line, but obviously this means there must be command line arguments and I'm also not sure whether there could sometimes be arguments in @ARGV when called through CGI? Is there a better way to check? The proper way would be use constant RUNNING_AS_CGI => exists $ENV{GATEWAY_INTERFACE}; -- fxn -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Detecting whether a script was called via CGI or the command line
Hi, I have a script which is usually run through CGI, but I want to set it up to be executed by a cron job each day too. Within the script I want to know where it was executed from; CGI or command line/cron job. I'm currently checking @ARGV to do this i.e. if there is data in @ARGV then it was called from the command line, but obviously this means there must be command line arguments and I'm also not sure whether there could sometimes be arguments in @ARGV when called through CGI? Is there a better way to check? TIA Cheers, Nigel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Win32 script cannot read command line argument.
Hi David, Thanks a lot! It works -) My association was "C:\Perl\bin\perl.exe" "%1" Vladimir - Original Message - From: "Wagner, David --- Senior Programmer Analyst --- WGO" <[EMAIL PROTECTED]> To: "Vladimir Lemberg" <[EMAIL PROTECTED]>; Sent: Wednesday, May 02, 2007 2:11 PM Subject: RE: Win32 script cannot read command line argument. -Original Message- From: Vladimir Lemberg [mailto:[EMAIL PROTECTED] Sent: Wednesday, May 02, 2007 14:01 To: beginners@perl.org Subject: Win32 script cannot read command line argument. Hi All, My script is unable to read argument when I'm executing it as: script.pl . However, when I'm running it as: perl script.pl - it works fine. I did associate perl scripts with Perl as explained in ActivePerl-Winfaq4.htm All my scripts, which doesnt require any arguments works file. Your folder assocation looks like: "C:\Perl\bin\perl.exe" "%1" %* If like this, then should be working. Been using this for what seems like forever. I have WinXP with Service Pack 2. All appriciate any help to resolve it. Thanks, Vladimir Wags ;) David R Wagner Senior Programmer Analyst FedEx Freight 1.408.323.4225x2224 TEL 1.408.323.4449 FAX http://fedex.com/us ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Win32 script cannot read command line argument.
> -Original Message- > From: Vladimir Lemberg [mailto:[EMAIL PROTECTED] > Sent: Wednesday, May 02, 2007 14:01 > To: beginners@perl.org > Subject: Win32 script cannot read command line argument. > > Hi All, > > My script is unable to read argument when I'm executing it > as: script.pl . > However, when I'm running it as: perl script.pl - > it works fine. > > I did associate perl scripts with Perl as explained in > ActivePerl-Winfaq4.htm > All my scripts, which doesnt require any arguments works file. Your folder assocation looks like: "C:\Perl\bin\perl.exe" "%1" %* If like this, then should be working. Been using this for what seems like forever. > > I have WinXP with Service Pack 2. > > All appriciate any help to resolve it. > > Thanks, > Vladimir Wags ;) David R Wagner Senior Programmer Analyst FedEx Freight 1.408.323.4225x2224 TEL 1.408.323.4449 FAX http://fedex.com/us ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Win32 script cannot read command line argument.
Hi All, My script is unable to read argument when I'm executing it as: script.pl . However, when I'm running it as: perl script.pl - it works fine. I did associate perl scripts with Perl as explained in ActivePerl-Winfaq4.htm All my scripts, which doesnt require any arguments works file. I have WinXP with Service Pack 2. All appriciate any help to resolve it. Thanks, Vladimir
Re: Command line fed to Perl was Re: File::Find again
From: Alan <[EMAIL PROTECTED]> > It's a different case here ie not a var, instead it's a command line that's > entered into a shell, such command line being passed to Perl. And the > command needs to make it to Perl without getting altered before it gets to > Perl. > > -s "\.properties$" > > In that part of the command line, in this case the $ happens to also be a > bash > shell meta (or possibly interpreted) character. > > In this context, I was alledging that perhaps the quotes (on that command > line) tell the bash shell to keep it literal (do not interpret the special > character $). > > But, I don't know much. I guess there's even a way to run a Perl script > without going through a shell in order to run the Perl script. If so, I > don't know how to do it. Sorry, I was not paying attention to the thread so I may be off. If you mean from within another script you may use the multiple parameter form of system(): system( $^X, $path_to_script, $param1, $param2, $param3); This way the shell is not involved in any way. Though of course it also means that you can't specify any redirection or anything like that this way. Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Command line fed to Perl was Re: File::Find again
On Monday 26 March 2007 07:32, Dave Gray wrote: > On 3/25/07, Alan <[EMAIL PROTECTED]> wrote: > > On Sunday 25 March 2007 18:14, Matt Herzog wrote: > > > This is all I needed. I swear I had " /($searchstring)/; " in there at > > > some point before . . . so if I pass it > > > > > > -s "\.properties$" > > > > > > at the command line, it works as expetcted. Nice. > > > > That might be a shell thing? > > > > In Linux bash shell those quotes (I think) tell the shell to not > > interpret anything inside the quotes. > > bash quotes work like perl quotes: > > echo "$PS1" > echo '$PS1' It's a different case here ie not a var, instead it's a command line that's entered into a shell, such command line being passed to Perl. And the command needs to make it to Perl without getting altered before it gets to Perl. -s "\.properties$" In that part of the command line, in this case the $ happens to also be a bash shell meta (or possibly interpreted) character. In this context, I was alledging that perhaps the quotes (on that command line) tell the bash shell to keep it literal (do not interpret the special character $). But, I don't know much. I guess there's even a way to run a Perl script without going through a shell in order to run the Perl script. If so, I don't know how to do it. -- Alan. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Multiple character command line switch
You can access the command line parameters directly without any module with @ARGV. Not sure if this helps. myScript -f1 -f2 Something like this might work: for ( $i = 0; $i < [EMAIL PROTECTED] - 1; $i += 2 ) { hash{"AGV[$i]"} = AGV[$i + 1]; } print "FIle 1: $hash{'-f'}"; On 3/13/07, brajesh agrawal <[EMAIL PROTECTED]> wrote: Hi all, I was trying to write a script. I wanted to use multiple characters in command line switches. For example myScript -f1 -f2 now getopt or getopts allows only for single character switches (please correct me if its not true). Is there any module which will allow my to have multiple character switches. Thanks Brajesh -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Multiple character command line switch
> >Hi all, > >I was trying to write a script. I wanted to use multiple characters in >command line switches. >For example >myScript -f1 -f2 > >now getopt or getopts allows only for single character switches (please >correct me if its not true). >Is there any module which will allow my to have multiple character switches. May you take a look at Getopt::Long? http://search.cpan.org/~jv/Getopt-Long-2.36/lib/Getopt/Long.pm -- http://home.arcor.de/jeffpang/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/