[28434] in Perl-Users-Digest
Perl-Users Digest, Issue: 9798 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Oct 3 14:10:25 2006
Date: Tue, 3 Oct 2006 11:10:08 -0700 (PDT)
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, 3 Oct 2006 Volume: 10 Number: 9798
Today's topics:
Re: OS X and perldoc <sherm@Sherm-Pendleys-Computer.local>
Re: OS X and perldoc <sherm@Sherm-Pendleys-Computer.local>
Re: perl flawed or my fault <bik.mido@tiscalinet.it>
Re: perl flawed or my fault <bik.mido@tiscalinet.it>
Re: perl flawed or my fault <emschwar@pobox.com>
Re: Please help me pass an array from VBA to Perl and p <bik.mido@tiscalinet.it>
Re: Text::CSV_XS Trying to find empty field <glex_no-spam@qwest-spam-no.invalid>
Re: this is annoying anno4000@radom.zrz.tu-berlin.de
Re: this is annoying <bik.mido@tiscalinet.it>
Re: this is annoying <jgibson@mail.arc.nasa.gov>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 03 Oct 2006 12:47:33 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: OS X and perldoc
Message-Id: <m2lknxbb2y.fsf@Sherm-Pendleys-Computer.local>
Justin C <justin.0610@purestblue.com> writes:
> I've recently bought a Mac, my first, and I'm still finding my way
> around it. I'm also still finding my way around Perl; while I don't have
> a lot of chance to use it I read a lot here and hope to pick things up.
> Quite often questions are posted and the OP is directed to perldoc and
> out of interest I follow. That was all well and good on my Linux box;
> it's not so good here. There was a recent reference to perldoc perlop,
> I've not read it all and I was interested in the answer to the OP's
> question. It seems that there is only a partial perldoc install on this
> machine, "perldoc -f" works, perldoc -m works, perldoc perldoc and
> perldoc perlop don't (I can't think of others to try ... not without
> perldoc perldoc anyway!).
>
> Where can I go for information on how to fix this install?
Many of Perl's pods are included in the 'DevDocumentation.pkg' sub-package
of the Xcode install.
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: Tue, 03 Oct 2006 12:48:34 -0400
From: Sherm Pendley <sherm@Sherm-Pendleys-Computer.local>
Subject: Re: OS X and perldoc
Message-Id: <m2hcylbb19.fsf@Sherm-Pendleys-Computer.local>
David Squire <David.Squire@no.spam.from.here.au> writes:
> These two work just fine on my Mac (latest OS X). I didn't do anything
> special to make that happen.
Yes you did:
> I have installed all the optional developer stuff
Don't know if I'd call that "special" or not, but that's what gave you the
missing pods. :-)
sherm--
--
Web Hosting by West Virginians, for West Virginians: http://wv-www.net
Cocoa programming in Perl: http://camelbones.sourceforge.net
------------------------------
Date: 3 Oct 2006 17:31:24 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perl flawed or my fault
Message-Id: <7uv4i25epn2gu19cougs8551l3o2hiequp@4ax.com>
On 2 Oct 2006 19:59:52 -0700, "paul" <betterdie@gmail.com> wrote:
>Subject: perl flawed or my fault
Without reading the rest, I guess the second one.
>use strict;
Good!
use warnings; # as well
>my $something = 'phal';
>my $otherthing = 'paul';
>
>my $note_whom = 'szmuzu\'mi';
>
>defined($something) ? $note_whom = $something : $otherthing =
>'singapore';
Huh?!? There's a lesson in this, precisely that C<?:> is not a
shortcut for C<if> and C<else> although in some situations it can be
used like that. But you'd better use it for what it's for, i.e. its
return value.
>print "$note_whom \n $otherthing \n";
>
>The result is: singapore
> singapore
That's not what I get:
C:\temp>perl foo.pl
singapore
paul
Which does make sense since assignment has a lower priority than
C<?:>.
C:\temp>perl -MO=Deparse,-p foo.pl
use strict 'refs';
(my $something = 'phal');
(my $otherthing = 'paul');
(my $note_whom = q[szmuzu'mi]);
((defined($something) ? ($note_whom = $something) : $otherthing) =
'singapore');
print("$note_whom \n $otherthing \n");
foo.pl syntax OK
>I don't know why the scalar $note_whom get the value that is assigned
>to $otherthing.
>
>Please give me the explaination, and thank you.
See above. But then, what did you expect, and what did you want?
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 3 Oct 2006 17:34:07 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: perl flawed or my fault
Message-Id: <2j05i2t7v8ge25hm7ije4slgjf6ec4tu9k@4ax.com>
On Tue, 03 Oct 2006 03:44:34 GMT, "John W. Krahn"
<someone@example.com> wrote:
>Because of precedence you have:
>
>(defined($something) ? $note_whom = $something : $otherthing) = 'singapore';
>
>You need to add parentheses:
>
>defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');
"But you'd better avoid it altogether" missing...
Of course if it where
$note_whom = defined($something) ? $something : $otherthing;
which I suppose may be closer to what he really wants, then things
would be different.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: 02 Oct 2006 22:12:32 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: perl flawed or my fault
Message-Id: <87ven26nrj.fsf@localhost.localdomain>
"John W. Krahn" <someone@example.com> writes:
> Because of precedence you have:
>
> (defined($something) ? $note_whom = $something : $otherthing) = 'singapore';
>
> You need to add parentheses:
>
> defined($something) ? ($note_whom = $something) : ($otherthing = 'singapore');
Or better yet, write it out:
if (defined($something)) {
$note_whome = $something;
} else {
$otherthing = 'singapore';
}
I always recommend against the ?: operator unless it's for something
small and self-contained. I avoid using it except for rvalues, unless
not using it will make things unacceptably ugly. Yes, this is a vague
standard. Here' an exampe of what is acceptable:
my $foo = $bar ? 0 : 1;
Here's something that isn't:
($var == 'foo' and $bar < 6 or $x > $y) ? ($this = something($else, 'maybe') or die "um, I dunno") : call_cows($potatoes);
-=Eric
------------------------------
Date: 3 Oct 2006 17:20:17 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Please help me pass an array from VBA to Perl and populate it. Newbie at wits' end!
Message-Id: <hov4i2h6ra1smnpgo3orc5l6be9jc649ra@4ax.com>
On 2 Oct 2006 18:49:12 -0700, david.f.jenkins@usa.net wrote:
>I want to pass an empty container for a set of strings from VBA into
>Perl, do some stuff in Perl, and populate the Collection with a set of
>strings. I've stolen most of the PDK Perlctrl regex sample and made
>some small mods to it to meet my requirements.
Quite vague. Do you want some sort of IPC? I guess VBA does have a
means to run an external program. Can it gather the program's output?
If so, then just... do so! Or else, how 'bout using it to run perl,
have it write its output into a file, and then read its contents?
Or else I've completely misunderstood your question.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 03 Oct 2006 10:26:50 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Text::CSV_XS Trying to find empty field
Message-Id: <452280ad$0$25775$815e3792@news.qwest.net>
Pam wrote:
> Thank you that did work!!!
That's good to hear. You're welcome.
> The reason I included the Spreadsheet
> snipet is because I write to the spreadsheet.
I understand, however the issue was how to test the value, which
has nothing to do with the spreadsheet, and by including all of
that extra code it takes longer for anyone to debug.
>The last problem I am having is
> once I determine
> that there is no value I write to spreadsheet and format it with a
> highlighted color.
> Right now it ignores my writing to the spread sheet it finds the column
> 12 and lets me
> know there is no value but it won't allow me to do any writing. Can't
> figure out why.
> Can you see anything I am doing wrong. I can't find the problem.
It looks like your column is off by one.
>
> # Create a new CSV parsing object
> my $csv = Text::CSV_XS->new();
>
>
> # Row and column are zero indexed
> my $row = 0;
Again.. Please narrow your code down to something that can be a simple
so anyone can run it to see the issue.
e.g. $total isn't part of the problem, CSVFILE isn't defined, etc.
Sure, anyone could go back and cut and paste your previous posts,
but that's a big waste of everyone's time.
> my $total;
> my $count = 0;
>
>
> while (<CSVFILE>) {
> if ($csv->parse($_)) {
> my @Fld = $csv->fields;
>
> my $col = 0;
>
>
> foreach my $token (@Fld) {
> $worksheet->write($row, $col, $token, $format3);
Here, if $col was 11 and token was '', it'd write the empty string to
column 11.
>
> $col++;
Now $col would be 12.
> print "This is the column", $col, "\n";
>
> if (($col == 12) && ($token eq '' )) {
> print "No value for token\n";
>
> $worksheet->write($row, $col, "3G_Platform",
> $format2);
Then it'd write the '3G_Platform' to column 12, if $token was ''.
>
> print "Is it SETTING WRITE\n";
> }
Now, the next iteration, $col would still be 12, it'd over-write the
previous value, '3G_Platform', with whatever $token contains,
and continue with the rest of the columns.
I'd suggest moving $col++ to the end of the for loop and adding in a
print, instead of a write, so you can see the values on STDOUT, as it's
running. Also, to make it easier to debug, change your input to be just
one line, containing the data you're testing for, that way you'll have
much less data to view on the screen.
# Assuming format2 is correct.. if not, print it out also.
#use Data::Dumper;
#
#print "format2=", Dumper( $format2 ), "\n";
for my $token( @Fld )
{
$token = '3G_Platform' if $col == 12 and $token eq '';
#$worksheet->write($row, $col, $token, $format2);
print "write( $row, $col, $token )\n";
$col++;
}
Once the print shows the correct data for the particular row and column,
you should be able to use the write().
When you're debugging and/or asking for help, try to simplify the
problem and narrow down the issue. Are the values I'm expecting being
written to the correct row and column? Am I testing for the values
correctly? etc... Once the variables are correctly being set, then you
add in writing it as an XLS.
perldoc -q debug
------------------------------
Date: 3 Oct 2006 17:01:27 GMT
From: anno4000@radom.zrz.tu-berlin.de
Subject: Re: this is annoying
Message-Id: <4ofjb7FebffoU1@news.dfncis.de>
Mr P <MisterPerl@gmail.com> wrote in comp.lang.perl.misc:
> shift split /\s+/, @$tx;
>
> Type of arg 1 to shift must be array (not split) at
> /production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"
>
> shift ( split /\s+/, @$tx );
> (same error)
As Paul Lalli has noted in his excellent reply, the second argument
of split() should be a string, not an array. I'll assume $str instead
of @$tx.
Even then, what do you expect your code to do? You do nothing with
the return value of shift(), so that doesn't appear to be the point.
But even if Perl turned the list returned by split into an array
to suit you, the array would not be accessible after the statement
is done, so that doesn't seem to be the point either. So what is
it?
>
> It doesn't make sense that I can do:
>
> @array = arrayOp args
>
> but I can't do
>
> @array = arrayOp1 (arrayOp2 args)
How does this correspond to your code? Specifically, what are
arrayOp1 and arrayOp2? Is arrayOp1 shift() and arrayOp2 split()?
In that case, what is an array operator? Something like shift()
that operates on an array (but returns a single scalar)? Or something
like split() that works on one to three scalar arguments and returns
something array-like (a list)? Explain your terminology.
[...]
> should always try its best to turn "stuff" into an array, coercing
> lists if necessary
Well, Perl as it is doesn't do that for you. It does very little of
its DWIM with behind-the-scene processing. (I've heard mumblings
like "...if we keep the array/list distinction" from the Perl 6 corner,
so there my be hope.)
You can do it yourself however:
shift @{ [ split ' ', $str] };
What would be the advantage if Perl did that automatically? The
anonymous array (which is indeed decapitated by shift) isn't accessible.
The return value is easier and more efficiently captured by
my ( $x) = split ' ', $str;
Anno
------------------------------
Date: 3 Oct 2006 19:58:58 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: this is annoying
Message-Id: <dq85i21huvgj8uebp4ro3k1tl64r7pij70@4ax.com>
On 3 Oct 2006 06:24:55 -0700, "Mr P" <MisterPerl@gmail.com> wrote:
> shift split /\s+/, @$tx;
>
>Type of arg 1 to shift must be array (not split) at
>/production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"
>
> shift ( split /\s+/, @$tx );
>(same error)
>
>It doesn't make sense that I can do:
It *does* make sense. shift() does two things: it returns the first
element of an array and removes it from the array. It doesn't work
with a list. You can sunscript a list though:
(split /\s+/, @$tx)[0];
But you're aware that
: split /PATTERN/,EXPR,LIMIT
: split /PATTERN/,EXPR
: split /PATTERN/
: split Splits the string EXPR into a list of strings and returns that
Aren't you? So unless @$tx contains an "EXPR,LIMIT" couple you're
doing something strange.
> @array = arrayOp args
>
>but I can't do
>
> @array = arrayOp1 (arrayOp2 args)
You can do
shift @{[ split /\s+/, @$tx; ]}
but you don't really need the removing action (on the anonymous hash),
so I suggest just using subscripting.
>everything is almost always busted. This is "the stuff" of clean,
>concise syntax (chains) and they don't often work in Perl.
They do work. But they're not called the way you think they are.
Michele
--
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
.'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,
------------------------------
Date: Tue, 03 Oct 2006 10:59:03 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: this is annoying
Message-Id: <031020061059039773%jgibson@mail.arc.nasa.gov>
In article <1159881895.514987.307340@b28g2000cwb.googlegroups.com>, Mr
P <MisterPerl@gmail.com> wrote:
> shift split /\s+/, @$tx;
>
> Type of arg 1 to shift must be array (not split) at
> /production/fe/users/feot/acs/ACS_Spex.pm line 5, near "$tx )"
>
> shift ( split /\s+/, @$tx );
> (same error)
You don't explain what you are trying to do here. Since you are not
saving the split array, but presumably want to extract the first
element, why not just do, e.g.:
$x = ( split /\s+/, $tx )[0];
(second argument to split fixed).
Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.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 V10 Issue 9798
***************************************