[30779] in Perl-Users-Digest
Perl-Users Digest, Issue: 2024 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Dec 2 14:09:51 2008
Date: Tue, 2 Dec 2008 11:09:16 -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 Tue, 2 Dec 2008 Volume: 11 Number: 2024
Today's topics:
Re: FAQ 8.44 How do I tell the difference between error <tadmc@seesig.invalid>
Re: FAQ 8.44 How do I tell the difference between error <bill@ts1000.us>
Re: FAQ 8.44 How do I tell the difference between error <tim@burlyhost.com>
Re: FAQ 8.44 How do I tell the difference between error <josef.moellers@fujitsu-siemens.com>
Noob trying to understand simple Perl grep statement <walterbyrd@iname.com>
Re: Noob trying to understand simple Perl grep statemen <willem@stack.nl>
Re: Noob trying to understand simple Perl grep statemen <someone@example.com>
Re: Noob trying to understand simple Perl grep statemen xhoster@gmail.com
Re: Noob trying to understand simple Perl grep statemen (J.D. Baldwin)
Re: Noob trying to understand simple Perl grep statemen <tadmc@seesig.invalid>
Re: Noob trying to understand simple Perl grep statemen <tadmc@seesig.invalid>
Re: Noob trying to understand simple Perl grep statemen <jurgenex@hotmail.com>
Re: Noob trying to understand simple Perl grep statemen <tadmc@seesig.invalid>
Re: Noob trying to understand simple Perl grep statemen <tadmc@seesig.invalid>
Re: perl segfault - how to troubleshoot <smallpond@juno.com>
Re: perl segfault - how to troubleshoot xhoster@gmail.com
Problem with call to system(), I think. <r.ted.byers@gmail.com>
Re: Problem with call to system(), I think. xhoster@gmail.com
Re: Problem with call to system(), I think. sln@netherlands.com
problem with print when \r is used. <kyeongyeon.song@gmail.com>
Re: problem with print when \r is used. <RedGrittyBrick@spamweary.invalid>
Re: problem with print when \r is used. <someone@example.com>
Re: problem with print when \r is used. <tadmc@seesig.invalid>
Re: subroutine to array <hjp-usenet2@hjp.at>
Re: suggestions for tree data structure xhoster@gmail.com
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 2 Dec 2008 07:16:47 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: FAQ 8.44 How do I tell the difference between errors from the shell and perl?
Message-Id: <slrngjad9v.ndu.tadmc@tadmc30.sbcglobal.net>
Bill H <bill@ts1000.us> wrote:
>> #!/usr/locl/bin/perl
^^^^
^^^^
> Ok maybe I need another cup of coffee, but what is the error?
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 2 Dec 2008 04:00:06 -0800 (PST)
From: Bill H <bill@ts1000.us>
Subject: Re: FAQ 8.44 How do I tell the difference between errors from the shell and perl?
Message-Id: <5b8839ba-b847-4b23-8ffd-bd83462a4658@l42g2000yqe.googlegroups.com>
On Dec 1, 9:03=A0pm, PerlFAQ Server <br...@stonehenge.com> wrote:
> =A0 =A0 Consider this script, which has an error you may not notice immed=
iately.
>
> =A0 =A0 =A0 =A0 =A0 =A0 #!/usr/locl/bin/perl
>
> =A0 =A0 =A0 =A0 =A0 =A0 print "Hello World\n";
>
> =A0 =A0 I get an error when I run this from my shell (which happens to be=
bash).
> =A0 =A0 That may look like perl forgot it has a print() function, but my =
shebang
> =A0 =A0 line is not the path to perl, so the shell runs the script, and I=
get
> =A0 =A0 the error.
Ok maybe I need another cup of coffee, but what is the error?
Bill H
------------------------------
Date: Tue, 02 Dec 2008 10:03:14 -0800
From: Tim Greer <tim@burlyhost.com>
Subject: Re: FAQ 8.44 How do I tell the difference between errors from the shell and perl?
Message-Id: <CLeZk.6366$v37.965@newsfe01.iad>
Bill H wrote:
> On Dec 1, 9:03Â pm, PerlFAQ Server <br...@stonehenge.com> wrote:
>
>> Consider this script, which has an error you may not notice
>> immediately.
>>
>> #!/usr/locl/bin/perl
^^^^
>> print "Hello World\n";
>>
....
> Ok maybe I need another cup of coffee, but what is the error?
>
> Bill H
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!
------------------------------
Date: Tue, 02 Dec 2008 13:48:43 +0100
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: FAQ 8.44 How do I tell the difference between errors from the shell and perl?
Message-Id: <gh3arb$oh5$1@nntp.fujitsu-siemens.com>
Bill H wrote:
> On Dec 1, 9:03 pm, PerlFAQ Server <br...@stonehenge.com> wrote:
>
>> Consider this script, which has an error you may not notice immediately.
>>
>> #!/usr/locl/bin/perl
>>
>> print "Hello World\n";
>>
>> I get an error when I run this from my shell (which happens to be bash).
>> That may look like perl forgot it has a print() function, but my shebang
>> line is not the path to perl, so the shell runs the script, and I get
>> the error.
>
> Ok maybe I need another cup of coffee, but what is the error?
IIUC:
-bash: print: command not found
Though, when I tried it, the error was
-bash: ./hello.pl: /usr/local/bin/perl: bad interpreter: No such file or
directory
which is not what the FAQ says. So this does not apply to all shells.
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: Tue, 2 Dec 2008 09:16:42 -0800 (PST)
From: walterbyrd <walterbyrd@iname.com>
Subject: Noob trying to understand simple Perl grep statement
Message-Id: <d51b4ac5-6b01-46d0-9fcb-197f17da1946@x16g2000prn.googlegroups.com>
This is from the perl objects book.
my @required = qw(preserver sunscreen water_bottle jacket);
my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
for my $item (@required) {
unless (grep $item eq $_, @skipper) { # not found in list?
print "skipper is missing $item.\n";
}
}
I don't understand this line:
unless (grep $item eq $_, @skipper)
I understand that $item is each item in the @required array. I am
guessing that the @required array is what is being grep'd. But what is
$_ ? Is that also each item from the @required array? If so, why not
just use the $item variable again? And what does >>$_, @skipper<<
mean? What is with the comma? Is that supposed to mean: grep $item
@skipper?
Is this supposed to check if the skipper is missing any required item?
Why not:
unless (grep $item @required eq grep $item @skipper)
------------------------------
Date: Tue, 2 Dec 2008 17:29:15 +0000 (UTC)
From: Willem <willem@stack.nl>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <slrngjas3b.1t19.willem@snail.stack.nl>
walterbyrd wrote:
) I don't understand this line:
)
) unless (grep $item eq $_, @skipper)
Let's break it into pieces then:
grep $item eq $_ , @skipper
grep <something> @skipper
Means: Return each item from @skipper for which <something> is true.
Furthermore, inside <something>, the variable $_ is the current item from
@skipper under consideration.
So:
grep $item eq $_ , @skipper
Means:
Return each item from @skipper for which >> $item eq $_ << is true.
Or in other words:
Return each item from @skipper that is equal to $item.
And the last bit is unless(), which means that the returned array is being
looked at as a truth value. An array is true if it contains elements.
Simple, huh ? Well, that's Perl for you. ;-)
SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT
------------------------------
Date: Tue, 02 Dec 2008 10:27:15 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <36fZk.7430$no6.1044@newsfe04.iad>
walterbyrd wrote:
> This is from the perl objects book.
>
> my @required = qw(preserver sunscreen water_bottle jacket);
> my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
> for my $item (@required) {
> unless (grep $item eq $_, @skipper) { # not found in list?
> print "skipper is missing $item.\n";
> }
> }
That can also be written as:
my @required = qw(preserver sunscreen water_bottle jacket);
my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
for my $item (@required) {
my $count;
for $_ (@skipper) {
$count++ if $item eq $_;
}
unless ($count) { # not found in list?
print "skipper is missing $item.\n";
}
}
> I don't understand this line:
>
> unless (grep $item eq $_, @skipper)
>
> I understand that $item is each item in the @required array. I am
> guessing that the @required array is what is being grep'd.
No, the @skipper array is being grep'd.
> But what is $_ ?
The value of the elements of @skipper.
> Is that also each item from the @required array? If so, why not
> just use the $item variable again? And what does >>$_, @skipper<<
> mean? What is with the comma? Is that supposed to mean: grep $item
> @skipper?
perldoc -f grep
grep EXPR,LIST
> Is this supposed to check if the skipper is missing any required item?
> Why not:
>
> unless (grep $item @required eq grep $item @skipper)
Because Perl does not work that way.
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
------------------------------
Date: 02 Dec 2008 18:28:43 GMT
From: xhoster@gmail.com
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <20081202132745.166$i8@newsreader.com>
walterbyrd <walterbyrd@iname.com> wrote:
> This is from the perl objects book.
>
> my @required = qw(preserver sunscreen water_bottle jacket);
> my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
> for my $item (@required) {
> unless (grep $item eq $_, @skipper) { # not found in list?
> print "skipper is missing $item.\n";
> }
> }
This would probably best be done with a hash rather than an array for at
least one of those structures.
>
> I don't understand this line:
>
> unless (grep $item eq $_, @skipper)
>
> I understand that $item is each item in the @required array. I am
> guessing that the @required array is what is being grep'd.
@skipper is what is being grepped. One time for each thing in @required
> But what is
> $_ ? Is that also each item from the @required array?
In the grep, $_ is set to each thing in the @skipper array in turn.
> If so, why not
> just use the $item variable again? And what does >>$_, @skipper<<
> mean?
In this context, nothing. You broken down the code incorrectly. The
grouping is
($item eq $_), @skipper
not
$item eq ($_,skipper)
Where the parentheses are meta language that indicate grouping for our
discussion, not necessarily to be taken as literal Perl syntax.
> What is with the comma? Is that supposed to mean: grep $item
> @skipper?
No, it means (about) the same thing as:
grep {$item eq $_} @skipper.
You provide grep with either a block with no comma, then a list; or an
expression then comma then a list. That is just how grep works.
See perldoc -f grep:
grep BLOCK LIST
grep EXPR,LIST
> Is this supposed to check if the skipper is missing any required item?
The overall code, yes. The grep part of the code just return a count
(Because it is invoked in a scalar context) of the things in @skipper which
equal whatever happens to be in $item at the moment. if the contents of
@skipper is unique, then this count will either be 0 (considered false) or
1 (considered true)
> Why not:
>
> unless (grep $item @required eq grep $item @skipper)
Because that wouldn't work. It is a syntax error at several levels,
and semantic error at several more.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 2 Dec 2008 18:35:23 +0000 (UTC)
From: INVALID_SEE_SIG@example.com.invalid (J.D. Baldwin)
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <gh3v5b$htq$1@reader1.panix.com>
In the previous article, walterbyrd <walterbyrd@iname.com> wrote:
> This is from the perl objects book.
>
> my @required = qw(preserver sunscreen water_bottle jacket);
> my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
> for my $item (@required) {
> unless (grep $item eq $_, @skipper) { # not found in list?
> print "skipper is missing $item.\n";
> }
> }
>
> I don't understand this line:
>
> unless (grep $item eq $_, @skipper)
>
> I understand that $item is each item in the @required array. I am
> guessing that the @required array is what is being grep'd. But what
> is $_ ? Is that also each item from the @required array? If so, why
> not just use the $item variable again? And what does >>$_,
> @skipper<< mean? What is with the comma? Is that supposed to mean:
> grep $item @skipper?
grep is taking two arguments, separated by the comma. They are:
1. $item eq $_
and
2. @skipper
The effect of this is to go through elements of @skipper, creating a
list out of the ones that equal $item (i.e., when the first arg
evaluates to "true." For any given $item, there will be only one
matching element (assuming items in @skipper are unique).
So, when $item is a member of @skipper, the grep will return a
one-element list consisting of that item. When $item is not found in
@skipper, the grep will return an empty list.
In the latter case, when grep returns an empty list, it will trigger
the block after the unless, printing the value of $item.
> Is this supposed to check if the skipper is missing any required item?
> Why not:
>
> unless (grep $item @required eq grep $item @skipper)
OK, first off, grep requires a comma or a block to be syntactically
correct.
Second, the first argument of grep is a truth-test, which determines
whether each given element of the array argument is passed into the
result list. If $item is non-null, then
grep $item, @required
will just be the same as @required (since $item is always true for a
non-empty string).
A revised version of your line:
unless (grep $item, @required eq grep $item, @skipper)
still has problems because the expression will be true if @required
and @skipper evaluate to the same value in scalar context. Probably
not what you intended.
--
_+_ From the catapult of |If anyone objects to any statement I make, I am
_|70|___:)=}- J.D. Baldwin |quite prepared not only to retract it, but also
\ / baldwin@panix.com|to deny under oath that I ever made it.-T. Lehrer
***~~~~----------------------------------------------------------------------
------------------------------
Date: Tue, 2 Dec 2008 11:51:50 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <slrngjatdm.q7r.tadmc@tadmc30.sbcglobal.net>
walterbyrd <walterbyrd@iname.com> wrote:
> This is from the perl objects book.
>
> my @required = qw(preserver sunscreen water_bottle jacket);
> my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
> for my $item (@required) {
> unless (grep $item eq $_, @skipper) { # not found in list?
> print "skipper is missing $item.\n";
> }
> }
>
> I don't understand this line:
>
> unless (grep $item eq $_, @skipper)
>
> I understand that $item is each item in the @required array. I am
> guessing that the @required array is what is being grep'd.
No, the @skipper array is what is being grep'd.
> But what is
> $_ ?
One of the elements from the @skipper array.
> And what does >>$_, @skipper<<
> mean? What is with the comma?
That is the syntax for calling grep:
perldoc -f grep
=item grep EXPR,LIST
It says that a comma is required after the expression.
(The expression for grep() is the "$item eq $_" part above).
> Is that supposed to mean: grep $item
> @skipper?
No, because that would be a syntax error.
> unless (grep $item @required eq grep $item @skipper)
More syntax errors...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 2 Dec 2008 11:48:29 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <slrngjat7d.q7r.tadmc@tadmc30.sbcglobal.net>
Willem <willem@stack.nl> wrote:
> walterbyrd wrote:
> ) I don't understand this line:
> )
> ) unless (grep $item eq $_, @skipper)
> And the last bit is unless(), which means that the returned array is being
> looked at
There is no returned array. There is not even a returned list.
There is only the return value from grep() in a scalar context.
perldoc -f grep
In scalar context, returns the number of times the expression was true.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 02 Dec 2008 10:40:50 -0800
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <g00bj4d64uhidogajmmgdoi9iob8racgie@4ax.com>
walterbyrd <walterbyrd@iname.com> wrote:
>This is from the perl objects book.
>
>my @required = qw(preserver sunscreen water_bottle jacket);
>my @skipper = qw(blue_shirt hat jacket preserver sunscreen);
>for my $item (@required) {
> unless (grep $item eq $_, @skipper) { # not found in list?
> print "skipper is missing $item.\n";
> }
>}
>
>I don't understand this line:
>
> unless (grep $item eq $_, @skipper)
>
>I understand that $item is each item in the @required array.
Correct.
> I am
>guessing that the @required array is what is being grep'd.
Wrong. It is the @skipper array, that is filtered. After all, that is
the one, that is passed as argument to grep.
>But what is
>$_ ? Is that also each item from the @required array?
No, it is subsequently set to each element of @skipper to test if $item
is equal to that element.
>If so, why not
>just use the $item variable again? And what does >>$_, @skipper<<
>mean? What is with the comma?
You are reading it wrong, adding some parenthesis to make the precedence
clearer:
grep ( {$item eq $_},
@skipper);
jue
------------------------------
Date: Tue, 2 Dec 2008 12:45:08 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <slrngjb0hk.qpp.tadmc@tadmc30.sbcglobal.net>
J.D. Baldwin <INVALID_SEE_SIG@example.com.invalid> wrote:
> If $item is non-null, then
>
> grep $item, @required
>
> will just be the same as @required (since $item is always true for a
> non-empty string).
$item = '0'; # a non-empty string that is NOT true...
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 2 Dec 2008 12:49:54 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: Noob trying to understand simple Perl grep statement
Message-Id: <slrngjb0qi.qrb.tadmc@tadmc30.sbcglobal.net>
Jürgen Exner <jurgenex@hotmail.com> wrote:
> walterbyrd <walterbyrd@iname.com> wrote:
> You are reading it wrong,
writing it wrong will probably not help... :-)
> adding some parenthesis to make the precedence
> clearer:
> grep ( {$item eq $_},
^
^
> @skipper);
grep ( {$item eq $_} # grep BLOCK LIST
@skipper);
or
grep ( $item eq $_, # grep EXPR,LIST
@skipper);
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 2 Dec 2008 07:31:15 -0800 (PST)
From: smallpond <smallpond@juno.com>
Subject: Re: perl segfault - how to troubleshoot
Message-Id: <0fdd6d66-ab26-4b19-af53-7b43ebd4074e@g38g2000yqd.googlegroups.com>
On Dec 1, 8:55 pm, James Harris <james.harri...@googlemail.com> wrote:
> Since a few days ago perl segfaults when running certain scripts. The
> scripts were ok before the problem started and have not been changed.
> I have checked my (Ubuntu) system for updates. None were made near the
> time of the first incidence of the problem so I started looking more
> widely.
>
> I found that even if I try to check syntax on one of the scripts that
> fails perl segfaults.
>
> $ perl -c mythrename.pl
> Segmentation fault
> $
>
> If I try to run the debugger it doesn't get as far as prompting for
> the first line
>
> $ perl -d mythrename.pl
> Loading DB routines from perl5db.pl version 1.28
> Editor support available.
> Enter h or `h h' for help, or `man perldebug' for more help.
>
> At this point CPU usage goes to 100%. Since I cannot even get the
> debugger to start at the first line where do I go next to try and fix
> this?
>
> Anyone else had similar problems recently - within a week?
>
> James
What perl version?
Was DB compiled for this perl version?
What 'use' or 'require' statements do you have?
Are you using threads?
-S
------------------------------
Date: 02 Dec 2008 16:57:40 GMT
From: xhoster@gmail.com
Subject: Re: perl segfault - how to troubleshoot
Message-Id: <20081202115642.550$Hs@newsreader.com>
James Harris <james.harris.1@googlemail.com> wrote:
> Since a few days ago perl segfaults when running certain scripts. The
> scripts were ok before the problem started and have not been changed.
> I have checked my (Ubuntu) system for updates. None were made near the
> time of the first incidence of the problem so I started looking more
> widely.
>
> I found that even if I try to check syntax on one of the scripts that
> fails perl segfaults.
>
> $ perl -c mythrename.pl
> Segmentation fault
> $
I'd run:
strace perl -c mythrename.pl
And capture the output. If it wasn't obvious what when wrong based on the
last thing before the segfault, then I'd grep out all of the file opens
(system libraries and such), and look at all those files to see if any
had changed recently.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 2 Dec 2008 08:34:31 -0800 (PST)
From: Ted Byers <r.ted.byers@gmail.com>
Subject: Problem with call to system(), I think.
Message-Id: <2c3e106f-c913-4d0f-b910-72ff3200fc01@y18g2000yqn.googlegroups.com>
Here is the simple loop with the problem:
print "\n\nProcessing merchant data: \n";
foreach $merchant(sort keys %merchants) {
print "\tmerchant name: $merchant\n\tmid: $merchants{$merchant}\n
\tAPI user name: $merchants_usernames{$merchant}\n\n";
system("activity.report.1.pl \"$merchant\" $merchants_usernames
{$merchant} $merchants{$merchant} $date_string 1>$dir\\activity.Report.
$merchant.stdout 2>$dir\\activity.Report.$merchant.stderr") == 0
or warn "Problem creating activity report for $merchant\n";
}
I am using "use strict" and $| = 1, from the top of the script.
The hash is fully populated and there are no null values in any
variable in the code shown.
The problem is that for 90% of the merchants, the script
activity.report.1.pl executes fine, producing the expected files
(those with the contents of stdout and stderr, as well as the desired
PDF file). For the rest, we get the merchant name, and the values
from the two hashes (that contain values to be provided as arguments
for the activity report script), followed by:
The process cannot access the file because it is being used by another
process.
Problem creating activity report for xxxxxxxxxxx xxxxxxx
The second line shown here is obviously from the die clause, but where
is the message "The process cannot access the file because it is being
used by another process." coming from? None of the information that
is written to stdout by the activity report script appears (e.g. the
first statement is to write to standard out the values of the
arguments), and nothing appears to be written to stderr either. The
files that ought to contain what is supposed to be written to stdout
and stderr don't even get created, hence my guess that the problem is
with the call to system.
Having previously printed out the contents of the hashes, I know the
correct arguments are being passed to "activity.report.1.pl" (from
comparing what was printed to the contents of the database table from
which the values are obtained, and what the activity report script
prints to standard out for the arguments it has received), and
activity.report.1.pl always runs to completion successfully when I
invoke it manually with all the same arguments that this script uses,
so I am at a loss. Why is my call to system failing (or how can I
find out), and what can be done to fix it? And why would it fail for
only 10% of the merchants?
Thanks
Ted
------------------------------
Date: 02 Dec 2008 17:35:31 GMT
From: xhoster@gmail.com
Subject: Re: Problem with call to system(), I think.
Message-Id: <20081202123433.146$1V@newsreader.com>
Ted Byers <r.ted.byers@gmail.com> wrote:
> system("activity.report.1.pl \"$merchant\" $merchants_usernames
> {$merchant} $merchants{$merchant} $date_string 1>$dir\\activity.Report.
> $merchant.stdout 2>$dir\\activity.Report.$merchant.stderr") == 0
Line wrapping really makes that code hard to read. But it could suck a
little less if you used the qq{} construct in place of the "", so that
literal double-quotes did not need to be escaped.
> or warn "Problem creating activity report for $merchant\n";
You should probably include $? and $! in the warning. It might help
and can't hurt.
...
> The problem is that for 90% of the merchants, the script
> activity.report.1.pl executes fine, producing the expected files
> (those with the contents of stdout and stderr, as well as the desired
> PDF file). For the rest, we get the merchant name, and the values
> from the two hashes (that contain values to be provided as arguments
> for the activity report script), followed by:
>
> The process cannot access the file because it is being used by another
> process.
> Problem creating activity report for xxxxxxxxxxx xxxxxxx
>
> The second line shown here is obviously from the die clause,
warn clause, not die clause
> but where
> is the message "The process cannot access the file because it is being
> used by another process." coming from?
I think it is coming from the shell-like-thingy that Perl spawns to run the
command.
It is a locking issue. I can reproduce the behavior on Windows simply by
opening the target activity.report.1.pl in Excel (which locks it).
I can solve the problem by invoking Perl explicitly in the system command,
rather than implicitly via the extension of the target:
system(qq{perl activity.report.1.pl blah blah blah}) ==0 or warn ...;
rather than:
system(qq{activity.report.1.pl blah blah blah}) ==0 or warn ...;
Although if something has your script locked while you are trying to run
it, maybe failure is the right thing to happen.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
Date: Tue, 02 Dec 2008 17:47:31 GMT
From: sln@netherlands.com
Subject: Re: Problem with call to system(), I think.
Message-Id: <imsaj41v4uqrfuads3p9esc198fpnv7j9i@4ax.com>
On Tue, 2 Dec 2008 08:34:31 -0800 (PST), Ted Byers <r.ted.byers@gmail.com> wrote:
>Here is the simple loop with the problem:
>
>print "\n\nProcessing merchant data: \n";
>foreach $merchant(sort keys %merchants) {
> print "\tmerchant name: $merchant\n\tmid: $merchants{$merchant}\n
>\tAPI user name: $merchants_usernames{$merchant}\n\n";
> system("activity.report.1.pl \"$merchant\" $merchants_usernames
>{$merchant} $merchants{$merchant} $date_string 1>$dir\\activity.Report.
>$merchant.stdout 2>$dir\\activity.Report.$merchant.stderr") == 0
> or warn "Problem creating activity report for $merchant\n";
>}
>
>I am using "use strict" and $| = 1, from the top of the script.
>
>The hash is fully populated and there are no null values in any
>variable in the code shown.
>
>The problem is that for 90% of the merchants, the script
>activity.report.1.pl executes fine, producing the expected files
>(those with the contents of stdout and stderr, as well as the desired
>PDF file). For the rest, we get the merchant name, and the values
>from the two hashes (that contain values to be provided as arguments
>for the activity report script), followed by:
>
>The process cannot access the file because it is being used by another
>process.
>Problem creating activity report for xxxxxxxxxxx xxxxxxx
>
[snip]
The docs say if shell metachars on a single scalar argument it
will pass the entire string unalterred to the shell command processor.
Otherwise it will split the arguments into words and pass to execvp().
In that case it couldn't hurt to try to create your own controlled
argument list. Try it with and without double quotes.
@args = (
"activity.report.1.pl",
"\"$merchant\"",
$merchants_usernames{$merchant},
$merchants{$merchant},
$date_string,
"1>$dir\\activity.Report.$merchant.stdout",
"2>$dir\\activity.Report.$merchant.stderr",
);
@args = (
"activity.report.1.pl",
"\"$merchant\"",
"\"$merchants_usernames{$merchant}\"",
"\"$merchants{$merchant}\"",
"\"$date_string\"",
"\"1>$dir\\activity.Report.$merchant.stdout\"",
"\"2>$dir\\activity.Report.$merchant.stderr\"",
);
system(@args) == 0 or die "system @args failed: $?"
sln
------------------------------
Date: Tue, 2 Dec 2008 08:10:00 -0800 (PST)
From: Cathy <kyeongyeon.song@gmail.com>
Subject: problem with print when \r is used.
Message-Id: <170c6886-1a8d-4b89-916b-da74d65de22b@z27g2000prd.googlegroups.com>
my $lines = 0;
my $current_line = 0;
my $percentage;
my $percentage_new;
open(my $FILE, "<", @ARGV[0]) or die "Can't open log file: $!";
while (sysread $FILE, $buffer, 4096) {
$lines += ($buffer =~ tr/\n//);
}
print "$lines lines\n";
close $FILE or die "$in: $!";
open(my $FILE, "<", @ARGV[0]) or die "Can't open log file: $!";
while(<$FILE>) {
$current_line += 1;
$percentage_new = sprintf("%d",$current_line / $lines * 100);
#$delta = $percentage_new - $percentage;
#print "$delta\n";
if($percentage_new - $percentage > 0) {
print "$current_line\n";
$percentage = $percentage_new;
}
}
Hi all,
This is my first post and I'm sorry if this is too easy question.
I wanted to indicate the progress of line number while reading a file.
In a source code above, it prints out total line number first, and
it prints out the line number whenever the percentage increases.
The problem is, when I put \r instead of \n, nothing is printed.
But if I remove 'if' statement, it prints out normally with \r.
Does anyone know what is wrong?
------------------------------
Date: Tue, 02 Dec 2008 16:21:02 +0000
From: RedGrittyBrick <RedGrittyBrick@spamweary.invalid>
Subject: Re: problem with print when \r is used.
Message-Id: <49356071$0$1338$fa0fcedb@news.zen.co.uk>
Cathy wrote:
> my $lines = 0;
> my $current_line = 0;
> my $percentage;
> my $percentage_new;
>
> open(my $FILE, "<", @ARGV[0]) or die "Can't open log file: $!";
>
>
> while (sysread $FILE, $buffer, 4096) {
> $lines += ($buffer =~ tr/\n//);
>
>
>
> }
>
>
> print "$lines lines\n";
> close $FILE or die "$in: $!";
>
> open(my $FILE, "<", @ARGV[0]) or die "Can't open log file: $!";
>
>
> while(<$FILE>) {
> $current_line += 1;
> $percentage_new = sprintf("%d",$current_line / $lines * 100);
>
>
> #$delta = $percentage_new - $percentage;
> #print "$delta\n";
> if($percentage_new - $percentage > 0) {
> print "$current_line\n";
> $percentage = $percentage_new;
> }
>
>
>
> }
>
>
> Hi all,
> This is my first post and I'm sorry if this is too easy question.
> I wanted to indicate the progress of line number while reading a file.
>
> In a source code above, it prints out total line number first, and
> it prints out the line number whenever the percentage increases.
> The problem is, when I put \r instead of \n, nothing is printed.
> But if I remove 'if' statement, it prints out normally with \r.
> Does anyone know what is wrong?
The standard output is line-buffered bu default - nothing is actually
output until a newline character. The way I turn off line-buffering is
by setting the special "autoflush" variable $| to a non-zero value. It
should be described somewhere in `perldoc perlvar` but see `perldoc -q
buffer`.
--
RGB
------------------------------
Date: Tue, 02 Dec 2008 10:34:16 -0800
From: "John W. Krahn" <someone@example.com>
Subject: Re: problem with print when \r is used.
Message-Id: <DcfZk.12249$%M6.9849@newsfe13.iad>
Cathy wrote:
>
> This is my first post and I'm sorry if this is too easy question.
> I wanted to indicate the progress of line number while reading a file.
>
> In a source code above, it prints out total line number first, and
> it prints out the line number whenever the percentage increases.
> The problem is, when I put \r instead of \n, nothing is printed.
> But if I remove 'if' statement, it prints out normally with \r.
> Does anyone know what is wrong?
Didn't you like the answer I gave you on the Perl beginners mailing list?
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
------------------------------
Date: Tue, 2 Dec 2008 11:55:58 -0600
From: Tad J McClellan <tadmc@seesig.invalid>
Subject: Re: problem with print when \r is used.
Message-Id: <slrngjatle.q7r.tadmc@tadmc30.sbcglobal.net>
Cathy <kyeongyeon.song@gmail.com> wrote:
> open(my $FILE, "<", @ARGV[0]) or die "Can't open log file: $!";
You should always enable warnings when developing Perl code.
--
Tad McClellan
email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
------------------------------
Date: Tue, 2 Dec 2008 15:50:31 +0100
From: "Peter J. Holzer" <hjp-usenet2@hjp.at>
Subject: Re: subroutine to array
Message-Id: <slrngjaipn.gin.hjp-usenet2@hrunkner.hjp.at>
On 2008-12-02 07:38, Tim Greer <tim@burlyhost.com> wrote:
> Tad J McClellan wrote:
>> sln@netherlands.com <sln@netherlands.com> wrote:
>>> if that is what you wan't.
>>
>>
>> if that is what you wa not?
>>
[...]
> doesn't understand simple contractions! It's easy, Lola - you just take
> two words, put them together, take out the middle letters, put in a
> comma, and you raise it up! -- Mitch Hedberg
http://www.youtube.com/watch?v=WPsChH5sTT4
hp
------------------------------
Date: 02 Dec 2008 17:56:04 GMT
From: xhoster@gmail.com
Subject: Re: suggestions for tree data structure
Message-Id: <20081202125505.817$fi@newsreader.com>
"freesoft12@gmail.com" <freesoft12@gmail.com> wrote:
> I have a file containing many paths (files/links/dirs) and to remove
> duplicate or redundant paths.
I can't figure out what "and to remove duplicate or redundant paths"
means.
> I want to open the file and read each
> path in that file and create a directory tree from it. Next, I want to
> copy that directory tree extracted from the file and move it
Which one is it, copy or move?
> underneath another directory (preserve the hierarchy).
>
> For example, my file contains the following paths:
>
> /a/b/c
> /a/b
> /a/b/d
>
> In the first path, 'c' is a regular file.
How do you know? Do you need to inspect the path/filename in Perl to
discover that, or do you know from some other part of the input file that
you haven't shown us?
> The second path can be
> ignored since it is already covered by the first path.
I'm not sure what that means. If /a/b/c implies /a/b, then why is /a/b in
the file in the first place? If /a/b is to be moved, what about /a/b/q,
which is not in your file but (perhaps) is in the file system?
> In the third
> path, 'd' is a symbolic link that points to (say) ../e/f (a regular
> file).
Again, how do you know that? Does your file tell you that, or do you have
to inspect 'd' from within Perl to figure that out?
>
> I want to move this directory tree underneath another directory, say /
> tmp. Hence I will have /tmp/a/b/c, /tmp/a/b/d -> /tmp/a/e/f.
On my filesystem, symbolic links containing .. are not materialized. So d
being a symbolic link to ../e/f and d being a symbolic link to /a/e/f are
two different things that happen to refer to the same file. But if you
move d someplace else, they no longer would refer to the same file.
I can't figure out how what you are trying to do differs from:
mv /a /tmp
> Can you suggest an efficient data structure to capture the directory
> tree information?
I suspect some kind of hash-based structure will be as efficient as it
needs to be. Without knowing what is actually supposed to happen, it is
hard to say.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.
------------------------------
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 2024
***************************************