[31004] in Perl-Users-Digest
Perl-Users Digest, Issue: 2249 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Mar 4 09:09:49 2009
Date: Wed, 4 Mar 2009 06:09:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Wed, 4 Mar 2009 Volume: 11 Number: 2249
Today's topics:
Handling external data <lvirden@gmail.com>
Re: Handling external data <noreply@gunnar.cc>
Re: Handling external data <cartercc@gmail.com>
Re: Handling external data <schaitan@gmail.com>
Re: Handling external data <tadmc@seesig.invalid>
new CPAN modules on Wed Mar 4 2009 (Randal Schwartz)
Re: system not returning correct return code. <xhoster@gmail.com>
system(@args) query, result not as expected. <justin.0903@purestblue.com>
Re: system(@args) query, result not as expected. <josef.moellers@fujitsu-siemens.com>
Re: system(@args) query, result not as expected. <schaitan@gmail.com>
Re: system(@args) query, result not as expected. <tadmc@seesig.invalid>
Re: system(@args) query, result not as expected. <syscjm@sumire.gwu.edu>
Re: system(@args) query, result not as expected. <josef.moellers@fujitsu-siemens.com>
Re: What-if algorithm <gamo@telecable.es>
Wholesale Sports Shoes Clear Air Force One AAA++quality <wujian3344@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 4 Mar 2009 05:00:59 -0800 (PST)
From: "Larry W. Virden" <lvirden@gmail.com>
Subject: Handling external data
Message-Id: <de421d09-a8b9-4c03-8970-44a3de9dc453@z9g2000yqi.googlegroups.com>
In a small application I am seeing the following. The program uses DBI
to fetch rows of information such as first and last names, then uses
the system() call to pass the information like this:
$message = "$first_name $last_name phone number: $phone";
system("mycommand arg1='abc' arg2='123 456' details='$message'");
While it works for most cases, this morning I hit the error
mycommand warning: the parameter "phone" is ignored.
mycommand warning: the parameter "number:" is ignored.
mycommand warning: the parameter "1234" is ignored.
sh: : cannot execute
Turns out that the user was John O'Smith - the ' is causing the system
command to parse wrong.
Now, I know I can use s/'// and remove the quote. But is there
anything I can do to get the ' to pass through unscathed?
I tried, for instance, using $last_name =~ s/'/\'/;
as well as s/'/\\'/ and s/'/\\'/ and s/'/\\\'/ and in each case, even
when I could see the \ was making it to the system command, it didn't
make it through the shell's parser.
Just wondering about alternate approaches. I tried using qq
($first_name $last_name phone number: $phone) , but that was just
bypassing things on the perl side.
------------------------------
Date: Wed, 04 Mar 2009 14:27:03 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Handling external data
Message-Id: <717dppFijeclU1@mid.individual.net>
Larry W. Virden wrote:
> In a small application I am seeing the following. The program uses DBI
> to fetch rows of information such as first and last names, then uses
> the system() call to pass the information like this:
>
> $message = "$first_name $last_name phone number: $phone";
>
> system("mycommand arg1='abc' arg2='123 456' details='$message'");
>
> While it works for most cases, this morning I hit the error
> mycommand warning: the parameter "phone" is ignored.
> mycommand warning: the parameter "number:" is ignored.
> mycommand warning: the parameter "1234" is ignored.
> sh: : cannot execute
>
> Turns out that the user was John O'Smith - the ' is causing the system
> command to parse wrong.
>
> Now, I know I can use s/'// and remove the quote. But is there
> anything I can do to get the ' to pass through unscathed?
>
> I tried, for instance, using $last_name =~ s/'/\'/;
> as well as s/'/\\'/ and s/'/\\'/ and s/'/\\\'/ and in each case, even
> when I could see the \ was making it to the system command, it didn't
> make it through the shell's parser.
>
> Just wondering about alternate approaches. I tried using qq
> ($first_name $last_name phone number: $phone) , but that was just
> bypassing things on the perl side.
Try:
my @args = ("mycommand", "arg1='abc'", "arg2='123 456'", $message);
system(@args);
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Wed, 4 Mar 2009 05:25:23 -0800 (PST)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: Handling external data
Message-Id: <1c017624-3588-4d8b-a5c7-92512b1a9af8@j12g2000vbl.googlegroups.com>
On Mar 4, 8:00=A0am, "Larry W. Virden" <lvir...@gmail.com> wrote:
> In a small application I am seeing the following. The program uses DBI
> to fetch rows of information such as first and last names, then uses
> the system() call to pass the information like this:
>
> $message =3D "$first_name $last_name phone number: $phone";
>
> system("mycommand arg1=3D'abc' arg2=3D'123 456' details=3D'$message'");
>
> While it works for most cases, this morning I hit the error
> mycommand warning: the parameter "phone" is ignored.
> mycommand warning: the parameter "number:" is ignored.
> mycommand warning: the parameter "1234" is ignored.
> sh: : cannot execute
>
> Turns out that the user was John O'Smith - the ' is causing the system
> command to parse wrong.
>
> Now, I know I can use s/'// and remove the quote. But is there
> anything I can do to get the ' to pass through unscathed?
>
> I tried, for instance, using $last_name =3D~ s/'/\'/;
> as well as s/'/\\'/ and s/'/\\'/ and s/'/\\\'/ and in each case, even
> when I could see the \ was making it to the system command, it didn't
> make it through the shell's parser.
>
> Just wondering about alternate approaches. I tried using qq
> ($first_name $last_name phone number: $phone) , but that was just
> bypassing things on the perl side.
It's not really clear to me where you are going wrong, but in general
this is a common problem. Here are four approaches that might help.
1. Use the q() operator, this won't interpolate values.
2. Escape the quote with the backslash operator.
3. Replace the quote with the ASCII octal value, \047.
4. Replace the quote with the HTML version, either " or '
As to your database read, this particular problem gave me such fits
that I converted my queries that read names to pipe delimited files:
John|O'Smith|888-555-1212
rather than
John','O'Smith','888-555-1212
Another gotcha is the space in the name, like 'van Rossum'
CC
------------------------------
Date: Wed, 4 Mar 2009 05:30:45 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: Handling external data
Message-Id: <8edd7e02-bf60-4195-a49b-e782771b1eb7@v13g2000pro.googlegroups.com>
Hi Larry, try this out:
#!/usr/bin/perl
use warnings;
use strict;
my $first_name = "John";
my $last_name = "O'Smith";
my $phone = 123;
my $message = "$first_name $last_name phone number: $phone";
print "Original message is $message\n";
$message =~ s|'|'\\''|g;
print "New message is $message\n";
system("echo myarg1='123 456' myarg2='$message'");
Check out the following from man 1 bash :
"Enclosing characters in single quotes preserves the literal value
of each character within the quotes. A single quote may not occur
between single quotes, even when preceded by a backslash."
So you can't pass it unscathed to the shell.....the only way to
preserve the odd single quote is to break the string before and after
it as 2 separate strings and treat the odd single quote itself as a
literally interpreted string in between........which makes 3 strings
out of John O'Smith :
'John O' + \' (backslash so as to treat it as literal) + 'Smith' =
'John O'\''Smith'
[bld@BLD-RHEL5-32 perl_progs]# echo 'John O'\''Smith'
John O'Smith
HTH,
Chaitanya
------------------------------
Date: Wed, 4 Mar 2009 07:31:20 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Handling external data
Message-Id: <slrngqt0l8.3ei.tadmc@tadmc30.sbcglobal.net>
Larry W. Virden <lvirden@gmail.com> wrote:
> $message = "$first_name $last_name phone number: $phone";
>
> system("mycommand arg1='abc' arg2='123 456' details='$message'");
>
> While it works for most cases, this morning I hit the error
> mycommand warning: the parameter "phone" is ignored.
> mycommand warning: the parameter "number:" is ignored.
> mycommand warning: the parameter "1234" is ignored.
> sh: : cannot execute
>
> Turns out that the user was John O'Smith - the ' is causing the system
> command to parse wrong.
>
> Now, I know I can use s/'// and remove the quote. But is there
> anything I can do to get the ' to pass through unscathed?
Your question is really about shell quoting.
AFAICT, there is no way to escape a single quote in a single quoted shell arg.
So use double quotes instead of single quotes.
system qq/mycommand arg1='abc' arg2='123 456' details="$message"/;
Or, better, avoid the shell altogether:
system 'mycommand', 'arg1=abc', 'arg2=123 456', "details=$message";
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 4 Mar 2009 05:42:25 GMT
From: merlyn@stonehenge.com (Randal Schwartz)
Subject: new CPAN modules on Wed Mar 4 2009
Message-Id: <KFyvup.1GAw@zorch.sf-bay.org>
The following modules have recently been added to or updated in the
Comprehensive Perl Archive Network (CPAN). You can install them using the
instructions in the 'perlmodinstall' page included with your Perl
distribution.
AProf-0.3
http://search.cpan.org/~unera/AProf-0.3/
is a profiler for periodically running processes
----
Algorithm-CurveFit-1.04
http://search.cpan.org/~smueller/Algorithm-CurveFit-1.04/
Nonlinear Least Squares Fitting
----
Algorithm-NGram-0.5
http://search.cpan.org/~revmischa/Algorithm-NGram-0.5/
----
Apache2-WURFLFilter-1.42
http://search.cpan.org/~ifuschini/Apache2-WURFLFilter-1.42/
is a Apache Mobile Filter that manage content (text & image) to the correct mobile device
----
App-Framework-0.03
http://search.cpan.org/~sdprice/App-Framework-0.03/
A framework for creating applications
----
Archive-Extract-0.31_02
http://search.cpan.org/~kane/Archive-Extract-0.31_02/
A generic archive extracting mechanism
----
Bio-Phylo-0.17_RC8
http://search.cpan.org/~rvosa/Bio-Phylo-0.17_RC8/
Phylogenetic analysis using perl.
----
CGI-ContactForm-1.50
http://search.cpan.org/~gunnar/CGI-ContactForm-1.50/
Generate a web contact form
----
CMS-JoomlaToDrupal-0.05
http://search.cpan.org/~hesco/CMS-JoomlaToDrupal-0.05/
migrate legacy Joomla content to Drupal
----
Capture-Tiny-0.05
http://search.cpan.org/~dagolden/Capture-Tiny-0.05/
Capture STDOUT and STDERR from Perl, XS or external programs
----
Catalyst-Model-DBIC-Schema-0.22
http://search.cpan.org/~bogdan/Catalyst-Model-DBIC-Schema-0.22/
DBIx::Class::Schema Model Class
----
Catalyst-Model-Data-Localize-0.00002
http://search.cpan.org/~dmaki/Catalyst-Model-Data-Localize-0.00002/
Catalyst Model Over Data::Localize
----
Catalyst-Model-Data-Localize-0.00003
http://search.cpan.org/~dmaki/Catalyst-Model-Data-Localize-0.00003/
Catalyst Model Over Data::Localize
----
Catalyst-Plugin-FirePHP-0.01_02
http://search.cpan.org/~willert/Catalyst-Plugin-FirePHP-0.01_02/
sends Catalyst log messages to a FirePHP console
----
Catalyst-Plugin-FirePHP-0.01_03
http://search.cpan.org/~willert/Catalyst-Plugin-FirePHP-0.01_03/
sends Catalyst log messages to a FirePHP console
----
DBIx-Class-Storage-Statistics-SimpleTable-0.01_01
http://search.cpan.org/~willert/DBIx-Class-Storage-Statistics-SimpleTable-0.01_01/
DBIC statistics in a table
----
Data-Entropy-0.005
http://search.cpan.org/~zefram/Data-Entropy-0.005/
entropy (randomness) management
----
Data-Hexdumper-2.01
http://search.cpan.org/~dcantrell/Data-Hexdumper-2.01/
Make binary data human-readable
----
Data-Localize-0.00004
http://search.cpan.org/~dmaki/Data-Localize-0.00004/
Alternate Data Localization API
----
Event-Join-0.01
http://search.cpan.org/~jrockway/Event-Join-0.01/
join multiple "events" into one
----
FFmpeg-Command-0.10
http://search.cpan.org/~mizzy/FFmpeg-Command-0.10/
A wrapper class for ffmpeg command line utility.
----
Geo-WebService-OpenCellID-0.05
http://search.cpan.org/~mrdvt/Geo-WebService-OpenCellID-0.05/
Perl API for the opencellid.org database
----
Hook-Output-File-0.06
http://search.cpan.org/~schubiger/Hook-Output-File-0.06/
Redirect STDOUT/STDERR to a file
----
IPC-Lite-0.1.28
http://search.cpan.org/~earonesty/IPC-Lite-0.1.28/
Share variables between processes
----
JE-0.031
http://search.cpan.org/~sprout/JE-0.031/
Pure-Perl ECMAScript (JavaScript) Engine
----
KinoSearch-0.164
http://search.cpan.org/~creamyg/KinoSearch-0.164/
search engine library
----
Lingua-LinkParser-1.11
http://search.cpan.org/~dbrian/Lingua-LinkParser-1.11/
Perl module implementing the Link Grammar Parser by Sleator, Temperley and Lafferty at CMU.
----
Math-Symbolic-0.602
http://search.cpan.org/~smueller/Math-Symbolic-0.602/
Symbolic calculations
----
MooseX-Declare-0.09
http://search.cpan.org/~flora/MooseX-Declare-0.09/
Declarative syntax for Moose
----
MooseX-Method-Signatures-0.12
http://search.cpan.org/~flora/MooseX-Method-Signatures-0.12/
Method declarations with type constraints and no source filter
----
Nagios-Plugin-0.32
http://search.cpan.org/~tonvoon/Nagios-Plugin-0.32/
A family of perl modules to streamline writing Nagios plugins
----
Net-Z3950-SimpleServer-1.10
http://search.cpan.org/~mirk/Net-Z3950-SimpleServer-1.10/
Simple Perl API for building Z39.50 servers.
----
Number-Phone-1.7001
http://search.cpan.org/~dcantrell/Number-Phone-1.7001/
base class for Number::Phone::* modules
----
Padre-Plugin-SVK-0.01
http://search.cpan.org/~szabgab/Padre-Plugin-SVK-0.01/
Simple SVK interface for Padre
----
Parse-CPAN-Meta-0.04_01
http://search.cpan.org/~smueller/Parse-CPAN-Meta-0.04_01/
Parse META.yml and other similar CPAN metadata files
----
Parse-Dia-SQL-0.03
http://search.cpan.org/~aff/Parse-Dia-SQL-0.03/
Convert Dia class diagrams into SQL.
----
Parse-Method-Signatures-1.003000
http://search.cpan.org/~ash/Parse-Method-Signatures-1.003000/
Perl6 like method signature parser
----
Path-Extended-0.04
http://search.cpan.org/~ishigaki/Path-Extended-0.04/
yet another Path class
----
Path-Extended-0.05
http://search.cpan.org/~ishigaki/Path-Extended-0.05/
yet another Path class
----
PerlCryptLib-1.07
http://search.cpan.org/~alvarol/PerlCryptLib-1.07/
Perl interface to Peter Guttman's cryptlib API
----
Pod-Abstract-0.14
http://search.cpan.org/~blilburne/Pod-Abstract-0.14/
Abstract document tree for Perl POD documents
----
Pod-POM-View-DocBook-0.04
http://search.cpan.org/~andrewf/Pod-POM-View-DocBook-0.04/
DocBook XML view of a Pod Object Model
----
Quote-Reference-1.0.1
http://search.cpan.org/~kilna/Quote-Reference-1.0.1/
Shortcut notation for whitespace-delimited array and hash references
----
SOAP-WSDL_XS-0.2
http://search.cpan.org/~mkutter/SOAP-WSDL_XS-0.2/
----
SQL-Abstract-1.49_04
http://search.cpan.org/~mstrout/SQL-Abstract-1.49_04/
Generate SQL from Perl data structures
----
Squatting-On-HTTP-Engine-0.02
http://search.cpan.org/~beppu/Squatting-On-HTTP-Engine-0.02/
run Squatting apps on top of HTTP::Engine
----
Squatting-On-HTTP-Engine-0.03
http://search.cpan.org/~beppu/Squatting-On-HTTP-Engine-0.03/
run Squatting apps on top of HTTP::Engine
----
Task-Catalyst-Tutorial-0.06
http://search.cpan.org/~mramberg/Task-Catalyst-Tutorial-0.06/
Installs everything you need to learn Catalyst
----
Task-Padre-Plugin-Deps-0.08
http://search.cpan.org/~fayland/Task-Padre-Plugin-Deps-0.08/
prereqs of Padre::Plugins
----
Task-Padre-Plugins-0.14
http://search.cpan.org/~fayland/Task-Padre-Plugins-0.14/
Get many Plugins of Padre at once
----
Template-Plugin-JSON-0.05
http://search.cpan.org/~nuffin/Template-Plugin-JSON-0.05/
Adds a .json vmethod for all TT values.
----
Template-Plugin-MultiMarkdown-0.03
http://search.cpan.org/~andrewf/Template-Plugin-MultiMarkdown-0.03/
TT plugin for Text::MultiMarkdown
----
Test-Able-0.04
http://search.cpan.org/~jdv/Test-Able-0.04/
xUnit with Moose
----
Test-XML-Deep-0.06
http://search.cpan.org/~jlavallee/Test-XML-Deep-0.06/
= XML::Simple + Test::Deep
----
Video-FrameGrab-0.02
http://search.cpan.org/~mschilli/Video-FrameGrab-0.02/
Grab a frame from a video
----
WebDAO-1.02
http://search.cpan.org/~zag/WebDAO-1.02/
platform for easy creation of high-performance and scalable web applications
----
WebDAO-Store-MLDBM-1.01
http://search.cpan.org/~zag/WebDAO-Store-MLDBM-1.01/
Implement session store using MLDBM
----
XML-Easy-0.001
http://search.cpan.org/~zefram/XML-Easy-0.001/
XML processing with a clean interface
----
XML-Grammar-Fortune-0.0107
http://search.cpan.org/~shlomif/XML-Grammar-Fortune-0.0107/
convert the FortunesXML grammar to other formats and from plaintext.
----
XML-Grammar-ProductsSyndication-0.0301
http://search.cpan.org/~shlomif/XML-Grammar-ProductsSyndication-0.0301/
an XML Grammar for ProductsSyndication.
----
XML-Grammar-ProductsSyndication-0.0302
http://search.cpan.org/~shlomif/XML-Grammar-ProductsSyndication-0.0302/
an XML Grammar for ProductsSyndication.
----
XML-Grammar-Screenplay-0.0501
http://search.cpan.org/~shlomif/XML-Grammar-Screenplay-0.0501/
CPAN distribution implementing an XML grammar for screenplays.
----
namespace-clean-0.11
http://search.cpan.org/~flora/namespace-clean-0.11/
Keep imports and functions out of your namespace
If you're an author of one of these modules, please submit a detailed
announcement to comp.lang.perl.announce, and we'll pass it along.
This message was generated by a Perl program described in my Linux
Magazine column, which can be found on-line (along with more than
200 other freely available past column articles) at
http://www.stonehenge.com/merlyn/LinuxMag/col82.html
print "Just another Perl hacker," # the original
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Smalltalk/Perl/Unix consulting, Technical writing, Comedy, etc. etc.
See http://methodsandmessages.vox.com/ for Smalltalk and Seaside discussion
------------------------------
Date: Tue, 03 Mar 2009 19:41:08 -0800
From: Xho Jingleheimerschmidt <xhoster@gmail.com>
Subject: Re: system not returning correct return code.
Message-Id: <49ae0fe8$0$30701$ed362ca5@nr5-q3a.newsreader.com>
Eric Pozharski wrote:
> On 2009-03-03, Ben Morrow <ben@morrow.me.uk> wrote:
>> Quoth omi <oakulkarni@gmail.com>:
>>> On Mar 3, 9:14 pm, omi <oakulka...@gmail.com> wrote:
>>>> Please see following snip of the code:
>>>>
>>>> $SIG{CHLD} = 'IGNORE';
>>>>
>>>> my $ret1 = `ls jjsjds`;
>>>> my $ret = $?;
>>>>
>>>> If we see the value of return code, that is not correctly set.
>>>> and this problem is coming because of the "$SIG{CHLD} = 'IGNORE';"
>>>> flag is set.
>> Yes. From the $? entry in perldoc perlvar:
>>
>> If you have installed a signal handler for "SIGCHLD", the value
>> of $? will usually be wrong outside that handler.
>>
>> On systems that honour "IGNORE" for SIGCHLD, it counts as a signal
>> handler. So don't do that.
>
> I would like that quote to be verified.
Which aspect?
> Look, right now I have a big
> deal of coding (testing mostly) about childs, pipes, etc. While
> experimenting I've set C<$SIG{CHLD} = sub { warn $? }>. And I was
> surprised to see C<0> as the inside value. I<$?> is set, and has proper
> value, but only after B<waitpid>. Wouldn't like some kind perlist with
> deeper insight comment on this?
$? is only set after the thing that sets it, yes. Being inside the
handler doesn't automatically cause $? to get set, it just means that
the sig handler that you are already in won't get in the way of it being
set, like it would if a sig handler exists but were you not in the sig
handler. (Which is not to say that other things couldn't get in the way
of $? being set correctly when inside a sig handler, just not the sig
handle itself.)
Xho
------------------------------
Date: Wed, 04 Mar 2009 11:16:03 -0000
From: Justin C <justin.0903@purestblue.com>
Subject: system(@args) query, result not as expected.
Message-Id: <50c3.49ae62f3.8b37e@zem>
I have the following:
my @args = ("mount", "-t smbfs -o username=boris,password=drowssap",
"\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
The error is *nix, not perl, but, please bear with me and read on. Here
is the error:
mount: unknown filesystem type 'password=drowssap"'
I chaned @args to be one string only:
my @args = ("mount -t smbfs -o username=boris,password=drowssap \"//255.255.255.255/Some Share with spaces\" /mnt/foo");
And it all works just fine. I thought that maybe @args weren't being
presented in order so a line just prior to 'system' I did a print, all
looked OK.
Any ideas why the mount command was thinking that 'password' was the
filesystem type?
Justin.
--
Justin C, by the sea.
------------------------------
Date: Wed, 04 Mar 2009 13:01:21 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <golqig$6t1$1@nntp.fujitsu-siemens.com>
Justin C wrote:
> I have the following:
>
> my @args = ("mount", "-t smbfs -o username=boris,password=drowssap",
> "\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
>
> The error is *nix, not perl, but, please bear with me and read on. Here
> is the error:
>
> mount: unknown filesystem type 'password=drowssap"'
>
> I chaned @args to be one string only:
>
> my @args = ("mount -t smbfs -o username=boris,password=drowssap \"//255.255.255.255/Some Share with spaces\" /mnt/foo");
>
> And it all works just fine. I thought that maybe @args weren't being
> presented in order so a line just prior to 'system' I did a print, all
> looked OK.
>
> Any ideas why the mount command was thinking that 'password' was the
> filesystem type?
Because it's in the same argument to "mount" as the "-t"-option:
"More than one type may be specified in a comma separated list."
(man mount).
I.e. "mount" thinks that you passed the following to specify the vfstype:
"-t smbfs -o username=boris,password=drowssap"
which it parses as two vfstypes:
" smbfs -o username=boris" and "password=drowssap".
I haven't looked into the source of "mount", but maybe "mount" tries the
first, which fails, tries the second, which also fails, and then issues
an error message for the second only.
Try putting each argument into a separate string:
my @args = ("mount", "-t", "smbfs", "-o",
"username=boris,password=drowssap",
"\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Wed, 4 Mar 2009 04:15:44 -0800 (PST)
From: Krishna Chaitanya <schaitan@gmail.com>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <1bf2ce34-1001-41a4-b344-e5f9f2cf1300@p6g2000pre.googlegroups.com>
It happens because Perl starts $args[0] with arguments $args[1], $args
[2], ... as if in single quotes which disables shell's mechanism to
evaluate and tokenize the string. Single quoting preserves everything,
including spaces, and this is what happens:
Listing: 1.pl
=============
#!/usr/bin/perl
use warnings;
use strict;
my @args = ("ls","-l /tmp");
eval {
system(@args);
};
if ($@) {
print "Error: $@\n";
}
Output:
=======
ls: invalid option --
Try `ls --help' for more information.
Now see how this is equivalent to the following at command prompt:
[bld@BLD-RHEL5-32 perl_progs]# 'ls' '-l /tmp'
ls: invalid option --
Try `ls --help' for more information.
And see this:
[bld@BLD-RHEL5-32 perl_progs]# 'ls' '-l' '/tmp'
total 8
drwxr-xr-x 2 root root 4096 Mar 4 07:05 chumma
-rw-r--r-- 1 root root 3 Feb 27 15:20 TEST
The last example above works because even though they are single-
quoted, there are no preserved spaces (which are basically the cause
of the problem here). So, like, Josef said, pass each argument on its
own and don't include any spaces in quotes. Or, like you figured out,
pass everything as a single string, which will be checked for shell
metacharacters and will be invoked as /bin/sh -c <command>.
-Chaitanya
------------------------------
Date: Wed, 4 Mar 2009 06:09:49 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <slrngqsrsd.2g1.tadmc@tadmc30.sbcglobal.net>
Justin C <justin.0903@purestblue.com> wrote:
>
> I have the following:
>
> my @args = ("mount", "-t smbfs -o username=boris,password=drowssap",
> "\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
>
> The error is *nix, not perl, but, please bear with me and read on. Here
> is the error:
>
> mount: unknown filesystem type 'password=drowssap"'
>
> I chaned @args to be one string only:
>
> my @args = ("mount -t smbfs -o username=boris,password=drowssap \"//255.255.255.255/Some Share with spaces\" /mnt/foo");
>
> And it all works just fine. I thought that maybe @args weren't being
> presented in order so a line just prior to 'system' I did a print, all
> looked OK.
>
> Any ideas why the mount command was thinking that 'password' was the
> filesystem type?
The 2nd sentence of the docs for the function you are using
explains it:
perldoc -f system
...
Note that argument processing varies depending on the
number of arguments...
You want mount's 1st arg to be "-t" and its 2nd arg to be "smbfs" etc,
but you have given this 1st arg instead:
-t smbfs -o username=boris,password=drowssap
Also, you want one of the args to be
//255.255.255.255/Some Share with spaces
but have given it
"//255.255.255.255/Some Share with spaces"
instead.
When you are using system() with many args, there is no shell involved.
When there is no shell, there is no need to protect spaces from the
shell's argument processing, so you don't need or want the double quotes.
You need to make each argument a separate element in the array:
my @args = (
'mount',
'-t',
'smbfs',
'-o',
'username=boris,password=drowssap',
'//255.255.255.255/Some Share with spaces',
'/mnt/foo',
);
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Wed, 04 Mar 2009 07:40:49 -0600
From: Chris Mattern <syscjm@sumire.gwu.edu>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <slrngqt171.hvj.syscjm@sumire.gwu.edu>
On 2009-03-04, Justin C <justin.0903@purestblue.com> wrote:
>
> I have the following:
>
> my @args = ("mount", "-t smbfs -o username=boris,password=drowssap",
> "\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
>
> The error is *nix, not perl, but, please bear with me and read on. Here
> is the error:
>
> mount: unknown filesystem type 'password=drowssap"'
>
> I chaned @args to be one string only:
>
> my @args = ("mount -t smbfs -o username=boris,password=drowssap \"//255.255.255.255/Some Share with spaces\" /mnt/foo");
>
> And it all works just fine. I thought that maybe @args weren't being
> presented in order so a line just prior to 'system' I did a print, all
> looked OK.
>
> Any ideas why the mount command was thinking that 'password' was the
> filesystem type?
Because you conflated the -o argument with the -t argument by making them
all one argument. Try this:
my @args = ("mount", "-t smbfs", "-o username=boris,password=drowssap",
"\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
When you made it all one string, you abdicated responsibility for separating
out your arguments and perl used the shell to do it, which it did correctly.
>
> Justin.
>
--
Christopher Mattern
NOTICE
Thank you for noticing this new notice
Your noticing it has been noted
And will be reported to the authorities
------------------------------
Date: Wed, 04 Mar 2009 14:50:25 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: system(@args) query, result not as expected.
Message-Id: <gom0v0$sum$1@nntp.fujitsu-siemens.com>
Chris Mattern wrote:
> On 2009-03-04, Justin C <justin.0903@purestblue.com> wrote:
>> I have the following:
>>
>> my @args = ("mount", "-t smbfs -o username=boris,password=drowssap",
>> "\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
>>
>> The error is *nix, not perl, but, please bear with me and read on. Here
>> is the error:
>>
>> mount: unknown filesystem type 'password=drowssap"'
>>
>> I chaned @args to be one string only:
>>
>> my @args = ("mount -t smbfs -o username=boris,password=drowssap \"//255.255.255.255/Some Share with spaces\" /mnt/foo");
>>
>> And it all works just fine. I thought that maybe @args weren't being
>> presented in order so a line just prior to 'system' I did a print, all
>> looked OK.
>>
>> Any ideas why the mount command was thinking that 'password' was the
>> filesystem type?
>
> Because you conflated the -o argument with the -t argument by making them
> all one argument. Try this:
>
> my @args = ("mount", "-t smbfs", "-o username=boris,password=drowssap",
> "\"//255.255.255.255/Some Share with spaces\"", "/mnt/foo");
This is only half-way and won't work:
"mount: unknown filesystem type ' smbfs'" (note the blank before "smbfs").
Josef
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html
------------------------------
Date: Wed, 4 Mar 2009 11:04:57 +0100
From: gamo <gamo@telecable.es>
Subject: Re: What-if algorithm
Message-Id: <alpine.LNX.2.00.0903041056290.4153@jvz.es>
On Tue, 3 Mar 2009, Xho Jingleheimerschmidt wrote:
> gamo wrote:
> >
> > In excel you have a menu function that consist of given one cell input and
> > one cell output no matter how are related one
> > to other, you could search for the input that correspond to a given value of
> > the output.
>
> You should probably tell us what that "menu function" is called.
> It sounds like either "goal seek" or the add-in "solver". You want some kind
Certainly I'm not refering to the solver. It is probably "goal seek."
> of numeric solver or function minimizer. There are all kinds of them out
> there, simplex, Levenberg Marquidt, steepest descent, Newtons method,
> conjugate gradient, etc. that have different areas of expertise. You can find
> several in "Numerical Recipes in C", for example. I haven't seen CPAN
> implementations of these in Perl that I liked.
>
> Xho
>
If and only if could be reduced to a root finding algorithm there is the
module Math::Function::Roots, that uses varios methods, i.e.
* bisection - Good for general purposes, you must provide a range in
which one and only one root exists. Basically a binary search for
the root.
* fixed_point - Only useful on a set of functions that can be
converted to a fixed-point function with certain properties, see
below. Fast when it can be used.
* secant - A fast converging algorithm which bases guesses on the
slope of the function. Because slope is used, areas of the function
where the slope is near horizontal (f'(x) == 0) should be avoided.
From which, I guess the bisection method it's the most general.
Best regards,
--
http://www.telecable.es/personales/gamo/
"Was it a car or a cat I saw?"
perl -E 'say 111_111_111**2;'
------------------------------
Date: Wed, 4 Mar 2009 04:42:45 -0800 (PST)
From: "wujian1@jian.com" <wujian3344@gmail.com>
Subject: Wholesale Sports Shoes Clear Air Force One AAA++quality
Message-Id: <1b07f60e-380e-4f1a-83a2-ac72ac0531bd@d19g2000prh.googlegroups.com>
supply sports shoes. The brand Sports shoes basketball shoes, Boot,
walling shoes, Athletic shoes, Jogging shoes, running shoes, leather
shoes, football, shoe sports shoe Footwear Sneaker, Shox Max Rift T-
shirts, womens t-shirts, Clothing womens clothing, wear hats Caps
Jersey jeans Sock Jacks, Watches, wallet, handbags, and Jeans Lady
Clothing and so on. Please contact us by email to get more
information. please kindly visite our website: http://www.cnnshoe.com
msn: cnnshoe2008@hotmail.com
email: cnnshoe@gmail.com
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2249
***************************************