[24290] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 6481 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 28 03:10:03 2004

Date: Wed, 28 Apr 2004 00:05: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           Wed, 28 Apr 2004     Volume: 10 Number: 6481

Today's topics:
    Re: a warning <matthew.garrish@sympatico.ca>
    Re: a warning <robin @ infusedlight.net>
    Re: A1 Triple Gold Star for Robin <spamtrap@dot-app.org>
    Re: A1 Triple Gold Star for Robin <noreply@gunnar.cc>
    Re: A1 Triple Gold Star for Robin (Walter Roberson)
        Another way to do this? <treborrude@SPAMBGONE.comcast.net>
    Re: Another way to do this? <tassilo.parseval@rwth-aachen.de>
        EMAIL: Extended Characters in SUBJECT field <nospam@spamfree.dud>
    Re: How can I create a PDF page with only Images (EPS & (Aqua)
        How to save lwp::useragent state? (John)
        I am so lost... sort and writing a shell script in Perl (Estella)
    Re: I am so lost... sort and writing a shell script in  <gnari@simnet.is>
    Re: multi-field array sort using Sort::Fields method <uri@stemsystems.com>
    Re: Newbie: Looking for comments on this (working) scri <ittyspam@yahoo.com>
    Re: Newbie: Looking for comments on this (working) scri <usenet@morrow.me.uk>
    Re: Newbie: Looking for comments on this (working) scri <ittyspam@yahoo.com>
    Re: Newbie: Looking for comments on this (working) scri <treborrude@SPAMBGONE.comcast.net>
    Re: Perl newbie q: trying to access array using variabl (m)
    Re: Perl newbie q: trying to access array using variabl <tadmc@augustmail.com>
        Perl programmers from Xalapa, Veracruz? <postmaster@castleamber.com>
        Perl Projects? <postmaster@castleamber.com>
    Re: Regex Matching Strings WITHOUT Chars <hal@thresholddigital.com>
    Re: Regex Matching Strings WITHOUT Chars <noreply@gunnar.cc>
    Re: Regex Matching Strings WITHOUT Chars <hal@thresholddigital.com>
    Re: Regex to format 1234 to 1,234 (pembed2003)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Tue, 27 Apr 2004 22:17:40 -0400
From: "Matt Garrish" <matthew.garrish@sympatico.ca>
Subject: Re: a warning
Message-Id: <5vEjc.25549$OU.614955@news20.bellglobal.com>


"Robin" <robin @ infusedlight.net> wrote in message
news:c6kq2e$18aa$1@news.f.de.plusline.net...
> When I installed perl builder (windows) with the default install with
> activestate perl, it crashed my @INC and it may have even deleted some of
> the which are supposed to be included in @INC, so let me advise you not to
> install this software.
>

Once again, would you care to elaborate on what "crashed my @INC" means to
you? Just to prove once again that you're full of crap, I downloaded and
installed the IDE without problem.

Instead of posting your half-baked warnings to Usenet, why don't you do
something useful with your time and contact the developers. If their
software really is the cause, I'm sure they'd like to know.

Matt




------------------------------

Date: Tue, 27 Apr 2004 21:54:35 -0800
From: "Robin" <robin @ infusedlight.net>
Subject: Re: a warning
Message-Id: <c6na1c$2jbi$1@news.f.de.plusline.net>

7
"Matt Garrish" <matthew.garrish@sympatico.ca> wrote in message
news:5vEjc.25549$OU.614955@news20.bellglobal.com...
>
> "Robin" <robin @ infusedlight.net> wrote in message
> news:c6kq2e$18aa$1@news.f.de.plusline.net...
> > When I installed perl builder (windows) with the default install with
> > activestate perl, it crashed my @INC and it may have even deleted some
of
> > the which are supposed to be included in @INC, so let me advise you not
to
> > install this software.
> >
>
> Once again, would you care to elaborate on what "crashed my @INC" means to
> you? Just to prove once again that you're full of crap, I downloaded and
> installed the IDE without problem.
>
> Instead of posting your half-baked warnings to Usenet, why don't you do
> something useful with your time and contact the developers. If their
> software really is the cause, I'm sure they'd like to know.
>
> Matt
>
well, perl was running fine... and then it wasn't it would start saying,
could not locate this or that file in @INC and then when I looked for the
file in my perl's folder, the files that @INC couldn't find weren't there.
Maybe the developers fixed this in their latest version?? Weird shit,
-Robin




------------------------------

Date: Tue, 27 Apr 2004 22:07:51 -0400
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: A1 Triple Gold Star for Robin
Message-Id: <_r2dnf08lOpkjBLdRVn-jw@adelphia.com>

Robin wrote:

> site, but saying that cgi.pm is less functional than insecure cgi parse
> code isn't kosher, at least not by my standards.

What she actually said was that CGI.pm is slower, and as far as that goes
she's right. It's a heavy weight module. A more modular approach, with CGI,
HTML, and Cookie functions in separate modules, would have been better than
the AllPurposeWebThing.pm that CGI.pm has grown into - but that's an old
argument.

The problem is that she was looking at CGI.pm vs. hand-rolled code in
isolation, and that's simply not a realistic scenario. In any real-world
app, the time spent processing the main body of the code will *completely*
dwarf that spent parsing the form input.

Just do the math.

Let's say profiling (with Devel::DProf) shows you that 1% of your overall
execution time is spent in CGI.pm, while 20% of it is spent in foo(). If
you can improve the efficiency of foo() by just 3%, to 19.4% of the overall
total, you've done more for the overall total than you would have by
cutting the cost of CGI.pm in half. If you can cut the cost of foo() in
half, you've done *far* more for the bottom line than *any* amount of work
on CGI.pm could possibly do.

In principle, we'd all be optimizing every last line of code to its peak
efficiency. Unfortunately, we just don't have time for that, so we have to
spend the time we do have where it will make the most difference.

> At the same time she does have a lot of good stuff to say.

She's funny, I'll give her that.

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


------------------------------

Date: Wed, 28 Apr 2004 04:24:23 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: A1 Triple Gold Star for Robin
Message-Id: <c6n4rf$dcqs0$1@ID-184292.news.uni-berlin.de>

Sherm Pendley wrote:
> Just do the math.
> 
> Let's say profiling (with Devel::DProf) shows you that 1% of your
> overall execution time is spent in CGI.pm, while 20% of it is spent
> in foo(). If you can improve the efficiency of foo() by just 3%, to
> 19.4% of the overall total, you've done more for the overall total
> than you would have by cutting the cost of CGI.pm in half. If you
> can cut the cost of foo() in half, you've done *far* more for the
> bottom line than *any* amount of work on CGI.pm could possibly do.

A benchmark I did showed that CGI.pm required about 0.2 seconds to
load and parse a simple query string. Do you write CGI apps that take
20 seconds to execute? I don't. And in that case your example is not
realistic. CGI.pm's inefficiency is apparently worse than you thought.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: 28 Apr 2004 04:20:08 GMT
From: roberson@ibd.nrc-cnrc.gc.ca (Walter Roberson)
Subject: Re: A1 Triple Gold Star for Robin
Message-Id: <c6nbdo$d52$1@canopus.cc.umanitoba.ca>

In article <c6n4rf$dcqs0$1@ID-184292.news.uni-berlin.de>,
Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote:
:A benchmark I did showed that CGI.pm required about 0.2 seconds to
:load and parse a simple query string. Do you write CGI apps that take
:20 seconds to execute? I don't.

You either:
a) replace your equipment with faster equipment when you get close to
the 20 second mark; or
b) do not work with expanding amounts of data; or
c) put strict limits on the amount of data that may be stored; or
d) have hypo-sub-log time search routines that you should be sharing
with the theoretical world.

Also, e) you must either not be locking your data, or else you have
worked out ways to guarantee that *all* simultaneous updates will be
completed and the data unlocked in time to make your 20 second window.


Sometimes there's just too much data to process in 20 seconds or less.
-- 
   Preposterous!! Where would all the calculators go?!


------------------------------

Date: Wed, 28 Apr 2004 05:02:48 GMT
From: "Trebor A. Rude" <treborrude@SPAMBGONE.comcast.net>
Subject: Another way to do this?
Message-Id: <YVGjc.32943$0u6.5898807@attbi_s03>

In an effort learn Perl, I was converting some of my smaller C++ programs to
Perl scripts. I had one program which printed out the bytes of an integer
as characters (so 0x616263 would be "abc"). I've got a Perl solution, but
for some reason it seems unnecessarily complicated. Is there a better way
to accomplish the same thing as the script below? I keep thinking that pack
or unpack can do it, but darned if I can figure out how.

#!/usr/bin/perl -w

use strict;

for (@ARGV)
{
  $_ = oct if /^0/;
  my @bytes;
  do { unshift @bytes, $_ & 0xFF; } while (($_ >>= 8) > 0);
  print chr for @bytes;
  print "\n";
}



------------------------------

Date: Wed, 28 Apr 2004 07:58:06 +0200
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: Another way to do this?
Message-Id: <c6nh5h$e4r5c$1@ID-231055.news.uni-berlin.de>

Also sprach Trebor A. Rude:

> In an effort learn Perl, I was converting some of my smaller C++ programs to
> Perl scripts. I had one program which printed out the bytes of an integer
> as characters (so 0x616263 would be "abc"). I've got a Perl solution, but
> for some reason it seems unnecessarily complicated. Is there a better way
> to accomplish the same thing as the script below? I keep thinking that pack
> or unpack can do it, but darned if I can figure out how.

Yes, pack() and unpack() are quite suitable for that.

> #!/usr/bin/perl -w
> 
> use strict;
> 
> for (@ARGV)
> {
>   $_ = oct if /^0/;
>   my @bytes;
>   do { unshift @bytes, $_ & 0xFF; } while (($_ >>= 8) > 0);
>   print chr for @bytes;
>   print "\n";
> }

In Perl this can be condensed into a one-liner:

    perl -le 'print unpack "A*", pack "H*", $_ for @ARGV' 0x616263 0x626364
    abc
    bcd

Or as a real script:

    print ((unpack "A*", pack "H*", $_), "\n") for @ARGV;
    
See 'perldoc -f pack'.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


------------------------------

Date: Wed, 28 Apr 2004 04:44:15 GMT
From: Sean O'Dwyer <nospam@spamfree.dud>
Subject: EMAIL: Extended Characters in SUBJECT field
Message-Id: <nospam-9657F7.00475528042004@nyctyp01-ge0.rdc-nyc.rr.com>

Using this code, as I've used for ages in many scripts, causes an error 
on a Spanish language site I'm devloping. 

      print MAIL "MIME-Version: 1.0\n";
      print MAIL "Content-type: text/plain; charset=iso-8859-1\n";
      print MAIL "Content-transfer-encoding: quoted-printable\n";
      print MAIL "Subject: Confirmacion\n\n";

"Confirmacion" should have an accent over the second "o" but my 
newsreader won't let me type the character directly.

The error is that sendmail sends the e-mail correctly, but the recipient 
sees the subject messily formatted as...

Subject: =?UNKNOWN?Q?Confirmaci=F3n?=

How can I encode this character properly in the script, so the accent 
appears over the "o"?

(The Perl source file is uploaded as ISO Western Latin 1.)

Thanks in advance,

Sean


------------------------------

Date: 27 Apr 2004 22:18:08 -0700
From: junk@dlink.org (Aqua)
Subject: Re: How can I create a PDF page with only Images (EPS & TIFF)
Message-Id: <55d7995c.0404272118.4398caab@posting.google.com>

> What happens if you do the following:
> 
> #!/usr/bin/perl
> use strict;
> use warnings;
> 
> use PDF::API2;
> 
> my $pdf = PDF::API2->new();
> my $page = $pdf->page();
> $page->mediabox('LETTER');
> my $gfx = $page->gfx();
> $gfx->image($pdf->image_jpeg("/path/to/some/jpg"), 100, 100);
> $gfx->circle(50, 50, 10);
> $gfx->stroke();
> 
> $pdf->saveas("/path/to/save/as");
> 
> __END__

This works for uncompressed TIFF. 

In case of PDF images I use
$gfx->image($pdf->pdfimage("/path/to/some/pdf"), 100, 100); 
and the output PDF is not viewable.

I tried PDF::Reuse and it works on PDF's. So temporarly I might
convert my images into PDF and use "Reuse" like

use PDF::Reuse;
use strict;

prFile('ex13.pdf');
prForm( {file => 'gr1.pdf',
       x => 20,
       y => 720});
prText(100, 500, 'This is put on the first page');
#prPage();
prForm('gr4.pdf');

prEnd();

BTW I wanted to try the same through Latex too.

Thanks and Regards
Dominic


------------------------------

Date: 27 Apr 2004 22:17:16 -0700
From: alkalox@hotmail.com (John)
Subject: How to save lwp::useragent state?
Message-Id: <3303a2cb.0404272117.482da475@posting.google.com>

Hello. I have a perl script that uses a LWP::Useragent 
to retrieve data from a password protected page. Here is
how I have set the authentication:

my $uagent = new LWP::UserAgent;
$uagent->agent('My Cool Browser');
$uagent->conn_cache(LWP::ConnCache->new());
$uagent->cookie_jar(HTTP::Cookies->new('file'=>cookies1',
'autosave'=>1,));
$uagent->credentials('www.mywebsite.com:80, 'test account', 'john'=>
'john123');
$myurl = 'http://www.mywebsite.com/secret';
$uagent->get($myurl);
print $uagent->content();

The above code works, but after doing a network trace it seems that
the user agent is logging in (HTTP authorization) each time it tries
to access the page (even if the page has been accessed before during
the same program session). A regular web browser does not behave like
this though -- once you log in, it does not try to keep logging in
during the same browser session. My question: is there any way to make
this behave a like a regular browser? Thanks.

John


------------------------------

Date: 27 Apr 2004 21:46:48 -0700
From: estellanewsgroup@hotmail.com (Estella)
Subject: I am so lost... sort and writing a shell script in Perl
Message-Id: <fe986fc1.0404272046.7b98956c@posting.google.com>

Hello, I just learnt Perl scripting, and I have been trying to do this
hw assignment, and I got so stuck in sorting a file with the key that
is calculated using the fields in the file. Here is what I have to do:

There is a file that contains county name, population size, water area
(in square miles), land area (in square miles).
Adams County	16428	4.73	1924.96
Asotin County	20551	5.34	635.34
Benton County	142475	57.03	1703.09
Chelan County	66616	72.25	2921.37
Clallam County	64525	930.89	1739.45
Clark County	345238	27.99	628.22
     ....

So we need to calculate the population density and water percentage,
and then print out the ascending order of the population density, and
also ascending order of the water percentage.

I did something like this, but I couldn't sort the list.
#!/net/local/bin/perl

while (<>) {	
	my($aa, $bb, $cc, $dd) = /^(\w+.+)\t(\d+)\t(\d+.\d+)\t(\d+.\d+)/ or
(warn "bad format on line $.:$_"), next;
	
	$popden = $bb/$dd;
	$waterpec = ($cc/($cc+$dd))*100;

	printf("%s %d %.2f%%\n", $aa, $popden, $waterpec);

	#open FH, ">> $tmp" or die $!;
}

foreach (sort keys %popden) {
	printf("%s %.2f %.2f%%\n", $aa, $popden, $waterpec);
}

I tried to look at a lot of sort examples online, but I am still
lost...is that something wrong with my logic? or I have to do
something more, like writing the list to a file first and then sort it
again..or..I dunno.
Thanks for helping...


------------------------------

Date: Wed, 28 Apr 2004 06:23:01 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: I am so lost... sort and writing a shell script in Perl
Message-Id: <c6nihe$fd7$1@news.simnet.is>

"Estella" <estellanewsgroup@hotmail.com> wrote in message
news:fe986fc1.0404272046.7b98956c@posting.google.com...
[assignment]

I am not going to do your assignment, but maybe a few hints

> while (<>)

> ...
>
> printf("%s %d %.2f%%\n", $aa, $popden, $waterpec);

probably you do not want to print out at this stage,
but rather collect the data in some sortable structure,
like an array
    push @list,[$aa, $popden, $waterpec];

>
> #open FH, ">> $tmp" or die $!;
it scares me to see this comment inside the loop!

> }
>

at this stage you need to figure out how to sort @list
by the correct value
 ...

and then
    foreach (@list) {
        printf("%s %.2f %.2f%%\n", $_->[0], $_->[1], $_->[2]);
    }






------------------------------

Date: Wed, 28 Apr 2004 04:28:00 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: multi-field array sort using Sort::Fields method
Message-Id: <x765bkafqo.fsf@mail.sysarch.com>

>>>>> "PL" == Paul Lalli <ittyspam@yahoo.com> writes:

  PL> On Tue, 27 Apr 2004, Domenico Discepola wrote:
  >> Thanks for your concrete example - it helps while trying to understand the
  >> existing documentation.  Although the example you provided works, I'm
  >> wondering if there is a CPAN module which provides a more "elegant"
  >> interface to a multi-field, multidimensional array sort.  What I have in
  >> mind is an interface similar to Sort::Fields:

  PL> I'm not especially sure I agree that your method would be more 'elegant'.
  PL> Really what you've suggested is to write a wrapper around sort() that
  PL> would restrict its functionality.  I'm not convinced that's a good idea.
  PL> (I'm also not sure I understand what you mean by your last sentence - $a
  PL> and $b are two predefined variables common to every single sort
  PL> subroutine, and cmp vs <=> simply means asciibettical vs numerical)

  PL> Disregarding all that, however, it probably wouldn't be too hard to write
  PL> such a wrapper:


  PL> sub with_elegance{
  PL> 	my $return;
  PL> 	foreach my $dimension (@$config){
  PL> 		my $pos = (abs $$dimension[0]) - 1;
  PL> 		my $compare;
  PL> 		if ($$dimension[1] eq 'a'){
  PL> 			$compare = 'cmp';
  PL> 		} elsif($$dimension[1] eq 'n') {
  PL> 			$compare = '<=>';
  PL> 		} else {
  PL> 			die "Invalid comparison marker: $$dimension[1] ".
  PL> 			     "(only 'a' and 'n' allowed\n";
  PL> 		}
  PL> 		if ($$dimension[0] >= 0){
  PL> 			eval '$return = $$a[$pos] '.$compare.' $$b[$pos]';
  PL> 		} else {
  PL> 			eval '$return = $$b[$pos] '.$compare.' $$a[$pos]';
  PL> 		}
  PL> 		last unless $return == 0;
  PL> 	}
  PL> 	return $return;
  PL> }

  PL> Give that a shot and see if it does what you want.  Note that I whipped
  PL> this up in just a few moments, and it shows.  Among the things that should
  PL> probably be fixed are the use of global variables, die() should become
  PL> carp or croak if this were put into an actual module, and the use of the
  PL> eval function.  Not to mention there's probably more than a few ways to
  PL> optimize it....

wait for Sort::Maker which is mostly developed and will do all that and
more and much faster and with a better api. i expect to cpan the .01
version in mid june before yapc. i could let people have beta copies
earlier than that if anyone wants it.

more on this soon as i do some more pod editing. i will post that soon
as it is presentable

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


------------------------------

Date: Tue, 27 Apr 2004 21:18:45 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Newbie: Looking for comments on this (working) script
Message-Id: <20040427205920.N25280@dishwasher.cs.rpi.edu>

On Tue, 27 Apr 2004, Robin wrote:

> "Paul Lalli" <ittyspam@yahoo.com> wrote in message
> >
> > Almost correct, actually.  A prototype of (@) tells perl "Only accept a
> > list of arguments" (as opposed to something like ($\@), which says "accept
> > a scalar value followed by an actual named array".  But accepting a list
> > of arguments is the default behavior for Perl subroutines.  Therefore,
> > using a prototype of (@) is no different than not using a prototype at
> > all.  (it is very different, however, from using an empty prototype, like
> > sub myfunc() )
> >
> > To clarify, prototypes do not have to have anything to do with references.
> > They can be used to restrict the number and type of arguments passed to
> > subroutines.  For example:
> >
> > sub myfunc($$) {
> >
> > This function will only accept two scalar values.  They can be any scalar
> > values you want, be them strings literals, numeric literals, named scalar
> > variables, or yes, references.  But the following function calls are all
> > permitted:
> >
> > myfunc("foo", 'bar');
> > myfunc(1, $string);
> > myfunc('', 0);
> >
> > none of which do any conversions to references.  In this case, the
> > prototype could be in place to cause fatal errors for any of these
> > function calls:
> >
> > myfunc ("foo", "bar", "baz");
> > myfunc (42);
> > myfunc ();
> > @ten = (1..10);
> > myfunc (@ten);
> >
> >
> > Paul Lalli
>
> Thanks, that's way more clear than the perldoc, in my humble opinion.
>
> Basically to clarify your intitial question, this prototype doesn't do
> anything because the arguments for a subroutine are already an array, @_,
> correct?
>

On the right track, but your wording can quickly lead to incorrectness.
All subroutine's arguments are always passed into the array @_, regardless
of prototype.  A prototype decides how many and what kind of arguments
will be allowed into that array.  For example
sub f1($@);
declares f1 to be a subroutine that will accept a single scalar followed
by a list of values.  Valid calls for this subroutine include:
f1($foo, @bar);
f1("hello", "world");
f1("hello", "how", "are", "you?");
f1(@arr1, $scal);

In this last case, the prototype would cause @arr1 to be automatically
referenced, and the remaining list would contain soley $scal.  So in the
function @_ would contain two elements - a reference to @arr1, and an
alias to $scal.

If you read the section on prototypes, it will tell you what each
identifier means.  $ is any scalar value, \$ is a named scalar variable, @
is a list of values, \@ is a named array variable, etc.

From this, you can see that @ is something of a catch-all, because in
Perl, any sequence of values is a list.  In the same way that
(@foo, @bar) = (1..10);
will cause @foo to contain 1 through 10, and @bar to contain nothing,
sub foo($@@)
is nonsensical because the first list identifier already covers any
following values.  In the general case then, it makes no sense for @ to
come anywhere but the last identifier in a prototype.  In the specific
case of sub foo (@);, the prototype isn't doing anything special - it's
just saying "take a list of values" which is exaclty what all perl
subroutines do anyway.

Is that clearer, or did I just muddy the explanation?

> One question, and I don't think this is in the perldoc perlsub, although I
> still haven't fully covered it, but can a subroutine, with strict in use, be
> called without parantheses in a script that's not a module after it has it's
> prototype? Or that's not a subroutine imported from a module?

Parentheses have little to nothing to do with a prototype.  However,
giving a subroutine a prototype requires that the compiler can see the
prototype before the subroutine is called.  For example, this code
generates a warning:

foo ("bar", "baz");

sub foo(\@$){
	print "In foo: $_[0], $_[1]\n";
}

In this case, the parser couldn't tell before you called foo() that foo()
had a prototype it should check.  So it outputted a warning and continued,
ignoring the prototype.

You are, btw, allowed to predeclare subroutines before defining them:

sub foo(\@$);

foo ("bar", "baz");

sub foo (\@$){
	print "In foo: $_[0], $_[1]\n";
}

This code will now generate a fatal error telling you you didn't properly
call foo().  The use of parentheses in calling the subroutine is optional,
because the subroutine was predeclared.  (This is standard procedure for
all subroutines, and is unaffected by the use of prototypes).

I hope that's clear,
Paul Lalli


------------------------------

Date: Wed, 28 Apr 2004 04:28:27 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Newbie: Looking for comments on this (working) script
Message-Id: <c6nbtb$18i$1@wisteria.csv.warwick.ac.uk>


Quoth Paul Lalli <ittyspam@yahoo.com>:
>
> sub f1($@);
> declares f1 to be a subroutine that will accept a single scalar followed
> by a list of values.  Valid calls for this subroutine include:
> f1($foo, @bar);
> f1("hello", "world");
> f1("hello", "how", "are", "you?");
> f1(@arr1, $scal);
> 
> In this last case, the prototype would cause @arr1 to be automatically
> referenced, and the remaining list would contain soley $scal.  So in the
> function @_ would contain two elements - a reference to @arr1, and an
> alias to $scal.

Not true. A prototype of $ causes that argument to be evaluated in
scalar context, i.e.

f1(@arr1, $scal);

is equivalent to

f1(scalar(@arr1), $scal);

which means that the first argument will be the *length* of the array,
not a ref to it.

Ben

-- 
   Razors pain you / Rivers are damp
   Acids stain you / And drugs cause cramp.                    [Dorothy Parker]
Guns aren't lawful / Nooses give
  Gas smells awful / You might as well live.                   ben@morrow.me.uk


------------------------------

Date: Wed, 28 Apr 2004 00:42:52 -0400
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: Newbie: Looking for comments on this (working) script
Message-Id: <20040428004124.L25280@dishwasher.cs.rpi.edu>

On Wed, 28 Apr 2004, Ben Morrow wrote:

> Quoth Paul Lalli <ittyspam@yahoo.com>:
> >
> > sub f1($@);
> > declares f1 to be a subroutine that will accept a single scalar followed
> > by a list of values.  Valid calls for this subroutine include:
> > f1($foo, @bar);
> > f1("hello", "world");
> > f1("hello", "how", "are", "you?");
> > f1(@arr1, $scal);
> >
> > In this last case, the prototype would cause @arr1 to be automatically
> > referenced, and the remaining list would contain soley $scal.  So in the
> > function @_ would contain two elements - a reference to @arr1, and an
> > alias to $scal.
>
> Not true. A prototype of $ causes that argument to be evaluated in
> scalar context, i.e.
>
> f1(@arr1, $scal);
>
> is equivalent to
>
> f1(scalar(@arr1), $scal);
>
> which means that the first argument will be the *length* of the array,
> not a ref to it.

Whoops.  You are correct of course.  My apologies for the faulty
information.  I should double check what I type when trying to inform
someone.

Paul Lalli


------------------------------

Date: Wed, 28 Apr 2004 04:47:51 GMT
From: "Trebor A. Rude" <treborrude@SPAMBGONE.comcast.net>
Subject: Re: Newbie: Looking for comments on this (working) script
Message-Id: <XHGjc.45153$GR.6577688@attbi_s01>

John W. Krahn wrote:

> "Trebor A. Rude" wrote:
>> 
>> sub run_id3v2 (@)
> 
> You don't really need the (@) prototype as that is the default behavior
> for subs.

Ok, then. Probably just my C++ habits coming through.

>> {
>>   my @command = ("id3v2", @_, $file);
> 
> Without the $file package variable this would be:
> 
>   my @command = ( 'id3v2', @_ );

I noticed you changed to single quotes from double quotes. Is it common to
use single quotes unless you need interpolative context? Again, probably my
C++ habits.

>>   my @output = `vorbiscomment -l \Q$file\E 2>&1`;
> 
> You could use chomp() here instead of later in map.
> 
>   chomp( my @output = `vorbiscomment -l \Q$file\E 2>&1` );

That probably works better, or at least makes the map a little easier to
understand. It seems stange to me to put a function around a variable
declaration, but that's just my C++ background yet again.

> 
>>   if ($? != 0)
>>   {
>>     print "Problems reading tags from $file, skipping it:\n", @output;
>>     next;
>>   }
>> 
>>   my %comments = map { chomp; split /=/, $_, 2 } @output;
> 
> Without the chomp() this would become:
> 
>   my %comments = map split( /=/, $_, 2 ), @output;
> 
> 
> However, it looks like you are not using anything after the '='.
> 
>   my @comments = map /^([^=]+)/, @output;

Now I'm confused. I was using the values of the %comments hash (which is
everything after the =, as the keys are everything before it) that's why
the map below contains $comments{$_}. In addition to that, I don't
understand your map statement. As I understand it, map returns a list which
is the result of applying the expression which is its first argumet to
every element of the list that is its second argument. But as far as I can
tell, the expression "/^([^=]+)/" doesn't do anything, leaving @comments as
an expensive copy of @output. Am I missing something, or did you mis-type
this statement?

> 
>>   my @arguments = ();
>> 
>>   # Also considered using (if this is strange indentation, thank
>>   # cperl-mode):
>>   #
>>   # push @arguments,
>>   #   map {($options{$_}, $comments{$_})}
>>   #     grep exists $options{$_}, keys %comments;
>> 
>>   push @arguments,
> 
> You are declaring @arguments and then pushing values into it.  Why not
> just assign the values when you declare it?
> 
>>     map {exists $options{$_} ? ($options{$_}, $comments{$_}) : ()}
>>       keys %comments;
> 
>     my @arguments =
>         map {exists $options{$_} ? ($options{$_}, $_) : ()}
>             @comments;

The reason I didn't set as the same time as delcaration was probably due to
my trying to decide which of the two statements to use (though I guess they
both could been declarations). 

I still don't see how your map statement produces the same result as mine
(but since I didn't understand your earlier map, maybe it's no surprise I
don't understand this).

At this stage of the program, %comments should look as though it were
declared like this:

%comments = (title => 'Untitled Hymn', artist => 'Chris Rice', album => 'Run
the Earth, Watch the Sky');

My map statement iterated over the keys from %comments, and if that key also
exists in %options, it would produce a list which was the value from
%options (so 'title' would go to '-t') and the value from %comments
(everything after the = in one of the lines of @output). That list
represents the arguments to the id3v2 program that are necessary to set a
tag in the mp3 file to the same value as the tag in the ogg file. I don't
see how you're duplicating that.

>>   $file =~ s/\.ogg/.mp3/;
> 
> You probably only want to match /\.ogg/ if it is at the end of $file.
> 
>    $file =~ s/\.ogg$/.mp3/;

You're right, forgot that.

Thanks for the advice so far. I hope we can work out our misunderstading of
the map issues.

Trebor



------------------------------

Date: 27 Apr 2004 18:34:39 -0700
From: mpepple@hotmail.com (m)
Subject: Re: Perl newbie q: trying to access array using variable name
Message-Id: <4af35cf2.0404271734.183ef9d8@posting.google.com>

yes... you are all very correct--this is not how i want to be doing
this :)

ever wish you could retract a post (you can't, can you?)?

a little digging later and a helpful phone call from an associate got
me on a more correct track.  thanks for your notes--i will put them to
good use.

matt


------------------------------

Date: Tue, 27 Apr 2004 23:31:33 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Perl newbie q: trying to access array using variable name
Message-Id: <slrnc8uct5.vhe.tadmc@magna.augustmail.com>

m <mpepple@hotmail.com> wrote:


> ever wish you could retract a post (you can't, can you?)?


Yes, you can.

   http://groups.google.com/groups?q=FAQ+cancel


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 28 Apr 2004 00:12:20 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Perl programmers from Xalapa, Veracruz?
Message-Id: <408f3d34$0$194$58c7af7e@news.kabelfoon.nl>

Just curious, any Perl programmers from Xalapa, Veracruz?

A monthly pm session might be a good start to learn a little Spanish and 
Perl :-D.

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


------------------------------

Date: Wed, 28 Apr 2004 00:10:01 -0500
From: John Bokma <postmaster@castleamber.com>
Subject: Perl Projects?
Message-Id: <408f3cab$0$194$58c7af7e@news.kabelfoon.nl>

Is there a site, besides http://jobs.perl.org/ that lists Perl projects 
available for freelance Perl programmers? Since I am desperatly looking 
for a (small) Perl project the more sites the better.

Only good quality sites, I found some bidding sites, but doing 40 hours 
of serious Perl coding for $ 5 / hour is not what I am looking for.

In case you have some work, let me know :-D

Thanks,
John

-- 
John                               MexIT: http://johnbokma.com/mexit/
                            personal page:       http://johnbokma.com/
    Experienced Perl programmer available:     http://castleamber.com/


------------------------------

Date: Wed, 28 Apr 2004 01:22:20 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Regex Matching Strings WITHOUT Chars
Message-Id: <gHDjc.31668$0u6.5673561@attbi_s03>

Sam Holden wrote:

> On Wed, 28 Apr 2004 00:40:21 GMT, Hal Vaughan <hal@thresholddigital.com>
> wrote:
>> I'm using Archive::Zip and I can specify, with a regex, the filenames
>> that
>> are added to an archive.  I have two types of log files, distinguishable
>> by
>> name types.  One ends with "-web-SL0" and the other ends with
>> "-server-SL0".  How can I specify, in a regex, to NOT match "web-SL0",
>> but to match all else?
>> 
>> I tried a few ideas, like specifying to match it 0 times:
>> 
>> /(web-SL0){0}/
> 
> That will just match everything, after all all strings contain a substring
> (of zero length) containing no copies of 'web-SL0'.
>> 
>> but it didn't work.  I also tried various combinations, like match all
>> chars
>> OR zero occurances of web-SL0, but nothing worked.  I've looked through
>> all my references, but I can't find a way to specify to NOT match a
>> pattern in
>> a regex.  Is it possible?
> 
> If the "end with" statement in the description is correct then:
> 
> /(?<!-web-SL0)$/
> 
> See the
> perldoc perlre
> documentation - search for "look-behind" for the description of the
> syntax.
> 
> 

Thanks.  I also got a private reply suggesting the same topic.  I had not
tried perlre -- tried perldoc -q regex, and variations on 
perldoc regex, re, or "regular expression", but perlre has stuff the others 
don't.  I had not even realized there would be more info specifically for 
perlre instead of regex or re -- just never thougth to add "perl" to it!

That'll do it.

Hal



------------------------------

Date: Wed, 28 Apr 2004 04:12:31 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regex Matching Strings WITHOUT Chars
Message-Id: <c6n457$dt5pe$1@ID-184292.news.uni-berlin.de>

I don't understand why everyone (except me) suggest solutions with 
extended regex patterns. It may be the most accurate answer to OP's 
literal question, but don't you forget the context? You don't need any 
extended pattern to exclude filenames matching a pattern when 
archiving files, do you? And isn't !/string/ an easier solution that 
would be preferable in this case?

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl



------------------------------

Date: Wed, 28 Apr 2004 02:22:53 GMT
From: Hal Vaughan <hal@thresholddigital.com>
Subject: Re: Regex Matching Strings WITHOUT Chars
Message-Id: <1AEjc.608$RE1.135450@attbi_s54>

Gunnar Hjalmarsson wrote:

> I don't understand why everyone (except me) suggest solutions with
> extended regex patterns. It may be the most accurate answer to OP's
> literal question, but don't you forget the context? You don't need any
> extended pattern to exclude filenames matching a pattern when
> archiving files, do you? And isn't !/string/ an easier solution that
> would be preferable in this case?
> 

Actually, your solution is much simpler (as to which is faster, I would not
know).  But, as an additional point, I am self taught, and learning about
look-behinds will be helpful, not just for this context, but in other
contexts.

In this particular case, using !/string/ was simpler and what I used in for
this particular problem.  However, there are some other problems I'm
working on with regexes, and for those, the look-behind will be a HUGE help
for me.

I also had missed a helpful topic in Perldoc, and the public responses
pointed that out (and a private response suggested something so obvious
that I had never thought of it -- to use "perldoc perldoc").  The holes in
one's experience if you're self-taught can be very frustrating, at times.

Hal


------------------------------

Date: 27 Apr 2004 21:59:20 -0700
From: pembed2003@yahoo.com (pembed2003)
Subject: Re: Regex to format 1234 to 1,234
Message-Id: <db593abd.0404272059.778eccc4@posting.google.com>

Tad McClellan <tadmc@augustmail.com> wrote in message news:<slrnc8todn.v6e.tadmc@magna.augustmail.com>...
> pembed2003 <pembed2003@yahoo.com> wrote:
> 
> > I am trying to come up with a regex to format number like:
>  
> > 1,234
> > -1,234
> > 1,234,567
> 
> 
> You are expected to check the Perl FAQ *before* posting to
> the Perl newsgroup you know...
> 
> 
>    perldoc -q commas
> 
>        How can I output my numbers with commas added?

perldoc -a 'got it'

Thanks!


------------------------------

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 6481
***************************************


home help back first fref pref prev next nref lref last post