[13939] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1349 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 11 12:10:32 1999

Date: Thu, 11 Nov 1999 09:10:19 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <942340218-v9-i1349@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 11 Nov 1999     Volume: 9 Number: 1349

Today's topics:
        Passing arrays + other arguments to a subroutine irf@netexecutive.com
    Re: Passing arrays + other arguments to a subroutine <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
    Re: Passing arrays + other arguments to a subroutine <rhomberg@ife.ee.ethz.ch>
    Re: Perl and commonsense part 2 ajmayo@my-deja.com
    Re: Perl and commonsense part 2 <rhomberg@ife.ee.ethz.ch>
    Re: Perl and commonsense part 2 <lr@hpl.hp.com>
    Re: Perl and commonsense part 2 (Bart Lateur)
    Re: Perl and commonsense part 2 <lr@hpl.hp.com>
    Re: Perl Extensions. Arrgh. <dan@tuatha.sidhe.org>
        Perl Interpreter in Java <nimi@sd.co.il>
    Re: perl_call_method and method existance (Randal L. Schwartz)
    Re: perl_call_method and method existance <dan@tuatha.sidhe.org>
        PHP problem <biyong_wu@hotmail.com>
    Re: PHP problem <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
    Re: PHP problem (Simon Cozens)
        Removing leading zeros from a string? (Burt lewis)
    Re: Removing leading zeros from a string? <vincent.murphy@cybertrust.gte.com>
    Re: Removing leading zeros from a string? <rhomberg@ife.ee.ethz.ch>
    Re: Removing leading zeros from a string? <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
    Re: Removing leading zeros from a string? <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
    Re: Removing leading zeros from a string? rafala@my-deja.com
        substitution: $& equals replaced text rafala@my-deja.com
    Re: use overload -- "0+" takes the place of "bool" <gellyfish@gellyfish.com>
    Re: Virus (Phil Goetz)
        Visual Package Manager (VPM) <mpauser@uswest.com>
    Re: weird bugs? (GiN)
    Re: Win32::Internet FTP List problem <lr@hpl.hp.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Thu, 11 Nov 1999 11:10:21 GMT
From: irf@netexecutive.com
Subject: Passing arrays + other arguments to a subroutine
Message-Id: <80e86s$ii7$1@nnrp1.deja.com>

i realise the arguments for a subroutine are stored in @_

so, within mySub(@xArray)
I can access the array elements by using, say, $aVar=$_[a].

however, what if i want to pass other arguments to the subroutine,
for example,

mySub(@xArray, $xVar, $yVar, zVar); ?

Now, within the sub, I would like to access $xVar by using $_[1],
$yVar by using $_[2] and so on.

I would also like to access each element of @xArray, in, say,
a block of code that would normally look like:
foreach $element(@xArray){ code; }

Of course, what happens is that $_[0]...$_[lengthOfxArray] become
the contents of @xArray, and $_[lengthOfxArray+1]=$xVar and so on.

So, how do i pass the array so that i can reference it with only
$_[0], and $_[1]=$xVar, $_[2]=yVar and so on?

I tried using a hard reference in the following attempt,
but it doesn't seem to work because I obviously don't understand how to
do it :)

---
@myArray=("go", "come", "as", "you", "are");
$text="any Text";

&refTest (\@myArray, $text);

sub refTest{
 #this is how i would like to access the array that is passed
  foreach $element(@$_[0]){
    print "myArray from sub: $key<BR>";
  }

 #Here is where I would like to access the second parameter
  print "$_[1]";
}
---

I would appreciate any pointers (no pun intended), thank you.


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 11 Nov 1999 03:26:37 -0800
From: Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Subject: Re: Passing arrays + other arguments to a subroutine
Message-Id: <1415c574.e31ff1c5@usw-ex0101-008.remarq.com>

In article <80e86s$ii7$1@nnrp1.deja.com>, irf@netexecutive.com wrote:
> i realise the arguments for a subroutine are stored in @_
> so, within mySub(@xArray)
> I can access the array elements by using, say, $aVar=$_[a].
> however, what if i want to pass other arguments to the subroutine,
> for example,
> mySub(@xArray, $xVar, $yVar, zVar); ?

How about making the @xArray the last argument? I couldn't quickly find
it but I'm fairly sure it says this somewhere in the docs - only one
array and it must be the last argument.

[Snip]

> I tried using a hard reference in the following attempt,
> but it doesn't seem to work because I obviously don't understand
> how to
> do it :)

perldoc perlsub
has examples of all this sort of thing.

HTH
--

Mark Bluemel
Not a Perl Hacker yet...


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Thu, 11 Nov 1999 13:42:01 +0100
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Passing arrays + other arguments to a subroutine
Message-Id: <382AB999.749E5049@ife.ee.ethz.ch>

irf@netexecutive.com wrote:
> 
> i realise the arguments for a subroutine are stored in @_
> 
> so, within mySub(@xArray)
> I can access the array elements by using, say, $aVar=$_[a].
> 
> however, what if i want to pass other arguments to the subroutine,
> for example,
> 
> mySub(@xArray, $xVar, $yVar, zVar); ?
> 
> Now, within the sub, I would like to access $xVar by using $_[1],
> $yVar by using $_[2] and so on.

I recommend against using $_[]. It is better to shift (or pop) the
contents into my-vars.

Here are three possibilites to pass an array and other args:
1. (Recommended) Array last:

sub mySub1 {
  my ($a,$b,$c) = (shift,shift,shift); #shift them from head of @_
  my @arr = @_;
  print "@arr -- $a,$b,$c\n";
}

2. Array first:

sub mySub2 {
  my ($c,$b,$a) = (pop,pop,pop);  #pop args from tail of @_
  my @arr = @_;
  print "@arr -- $a,$b,$c\n";
}

3. w/reference, see perlre manpage:

sub mySub3 {
  my ($arr, $a,$b,$c) = @_;
  #$arr is equivalent to @{$_[0}
  print "@$arr -- $a,$b,$c\n";
}


> sub refTest{
>  #this is how i would like to access the array that is passed
>   foreach $element(@$_[0]){

you will find in perlre that that this works only with braces:
@{$_[0]}, but that's still ugly.

- Alex


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

Date: Thu, 11 Nov 1999 14:59:04 GMT
From: ajmayo@my-deja.com
Subject: Re: Perl and commonsense part 2
Message-Id: <80eljm$s0m$1@nnrp1.deja.com>

In article <slrn82jo48.5av.dha@panix.com>,
  dha@panix.com (David H. Adler) wrote:
[an elegantly terse replacement for my code]

Thanks for the cunning code. I was, btw, omitting variable declarations
and use strict simply for brevity. You are correct in that I end up
with references to arrays but this does actually work - it is, as I
said, only references to *hashes* that cannot be stored in ASP session
variables. References to *arrays* work fine. I do not know why this is,
exactly. However, it solved the problem for my colleague.

I do think logically of an array of arrays even though technically I
suppose we are talking an array of anonymous array *references*.

As for your code. I understand qw but tend to use conventional quotes
more out of habit and the fact that I am working in several programming
languages in a single day, so it is a hard habit to break. Nice
feature, though - wish more languages had it.

Regarding the use of map, I frankly have to admit I haven't the
faintest idea how this works, and reading over the documentation
for 'map' I am not terribly enlightened, but I will persevere. The =>
operator is particularly baffling; I can't find this mentioned in
perlop at all. The map documentation says

QUOTE

    %hash = map { getkey($_) => $_ } @array;

is just a funny way to write


    %hash = ();
    foreach $_ (@array) {
        $hash{getkey($_)} = $_;

UNQUOTE

well, that may be so, but I still don't grok => in this context, I'm
afraid. This sort of has the flavour that Jerry Pournelle used to
call 'clear if already known' i.e whoever wrote that knew perfectly
well what they were talking about, but coming to it cold it is somewhat
baffling.



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 11 Nov 1999 16:44:59 +0100
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Perl and commonsense part 2
Message-Id: <382AE47B.80DBC129@ife.ee.ethz.ch>

ajmayo@my-deja.com wrote:

> Thanks for the cunning code. I was, btw, omitting variable declarations
> and use strict simply for brevity.

Don't do that. Look at some responses ot posted code. Most of them
complain about missing -w and use strict;

> Regarding the use of map, I frankly have to admit I haven't the
> faintest idea how this works, and reading over the documentation
> for 'map' I am not terribly enlightened, but I will persevere. The =>
> operator is particularly baffling; I can't find this mentioned in
> perlop at all. The map documentation says
> 
> QUOTE
> 
>     %hash = map { getkey($_) => $_ } @array;

From perlop:

The => digraph is mostly just a synonym for the comma operator.  It's
useful for documenting arguments that come in pairs.  As of release
5.001, it also forces any word to the left of it to be interpreted as a
string.

it is simply a comma that quotes the left part.
%myhash = (a=>4, b=>17) is easier to read than
%myhash = ('a',4,'b',17), as you can easily see keys and values.
(of course some would rather write ('a', 4=> 'b', 17) which is still the
same, but => used to confuse rather than to clarify)

- Alex


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

Date: Thu, 11 Nov 1999 08:10:12 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Perl and commonsense part 2
Message-Id: <MPG.12948a38510cacd298a1db@nntp.hpl.hp.com>

In article <80eljm$s0m$1@nnrp1.deja.com> on Thu, 11 Nov 1999 14:59:04 
GMT, ajmayo@my-deja.com <ajmayo@my-deja.com> says...
> In article <slrn82jo48.5av.dha@panix.com>,
>   dha@panix.com (David H. Adler) wrote:
> [an elegantly terse replacement for my code]
> 
> Thanks for the cunning code.

Wrong attribution.  It was I, and I'll happily take credit for 
'elegantly terse' and 'cunning'.  But I'm slightly embarrassed by '=>' 
(see below).

>                          I was, btw, omitting variable declarations
> and use strict simply for brevity. You are correct in that I end up
> with references to arrays but this does actually work - it is, as I
> said, only references to *hashes* that cannot be stored in ASP session
> variables. References to *arrays* work fine. I do not know why this is,
> exactly. However, it solved the problem for my colleague.

Amazing, because I wouldn't know how to reuse any reference written out 
as a string to an external device.

> I do think logically of an array of arrays even though technically I
> suppose we are talking an array of anonymous array *references*.

Most of us talk about an array of arrays, while thinking logically of an 
array of array *references*.  (Assuming most of us think logically at 
all. :-)

> As for your code. I understand qw but tend to use conventional quotes
> more out of habit and the fact that I am working in several programming
> languages in a single day, so it is a hard habit to break. Nice
> feature, though - wish more languages had it.

Indeed -- easy to write and to read; no downside I can think of.  Thank 
The Larry for that.

> Regarding the use of map, I frankly have to admit I haven't the
> faintest idea how this works, and reading over the documentation
> for 'map' I am not terribly enlightened, but I will persevere.

Understanding and using 'map' is a criterion for graduating from 
'novice' to 'intermediate' (to borrow levels of expertise from skiing).  
Investment in study and practice will repay itself in program 
performance and expressiveness (and clarity, assuming the reader groks 
it too).

>               The =>
> operator is particularly baffling; I can't find this mentioned in
> perlop at all.

You didn't look hard enough.  Searching perlop for '=>' led past '<=>' 
to this:

Comma Operator

Binary ``,'' is the comma operator. In scalar context it evaluates its 
left argument, throws that value away, then evaluates its right argument 
and returns that value. This is just like C's comma operator. 

In list context, it's just the list argument separator, and inserts both 
its arguments into the list. 

The => digraph is mostly just a synonym for the comma operator. It's 
useful for documenting arguments that come in pairs. As of release 
5.001, it also forces any word to the left of it to be interpreted as a 
string. 

>           The map documentation says
> 
> QUOTE
> 
>     %hash = map { getkey($_) => $_ } @array;
> 
> is just a funny way to write
> 
> 
>     %hash = ();
>     foreach $_ (@array) {
>         $hash{getkey($_)} = $_;
> 
> UNQUOTE
> 
> well, that may be so, but I still don't grok => in this context, I'm
> afraid. This sort of has the flavour that Jerry Pournelle used to
> call 'clear if already known' i.e whoever wrote that knew perfectly
> well what they were talking about, but coming to it cold it is somewhat
> baffling.

That is why I am slightly embarrassed.  It is an acquired taste, turning 
into a habit.

Several others and I like to use => ('fat comma') instead of plain old 
comma to differentiate 'categories' of members of a list; for example, 
separating the format of 'sprintf' from the operands.  Others abhor 
this.

Yesterday, Greg Bacon posted the following:

    push @array, substr $str, 0, 255 => '' while $string;

which startled even me!  (Grab and clip the start of a string 
repeatedly.)  But I like it, now that I'm over the shock.

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 11 Nov 1999 16:19:24 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: Perl and commonsense part 2
Message-Id: <382aea58.3820198@news.skynet.be>

ajmayo@my-deja.com wrote:

>Regarding the use of map, I frankly have to admit I haven't the
>faintest idea how this works, and reading over the documentation
>for 'map' I am not terribly enlightened, but I will persevere. 

It comes from Lisp, or similar languages. It says: "Apply this code
block to each item in the following list, and build a list of the
results.". Example:

	$, = " ";
	print map { 2 * $_ } 1 .. 10;

Which prints the even numbers from 2 till 20. It works by multiplying
each number between 1 and 10 in turn by two.

>The =>
>operator is particularly baffling; I can't find this mentioned in
>perlop at all.

It's a "fancy comma". It works like ",", except it has the habit of
autoquoting the thing on the left of it, if it is a bare word. So the
snippet (not "statement"):

	a => 123

is the same as

	'a', 123

It is designed to easily build hashes, where on the left there's a
literal hash key, and on the right there's a hash value. Example:

	%hash = ( a => \@one, b => \@two );

A hash key is ALWAYS a string, but a hash value can be any kind of
scalar value (e.g. a reference). That is why "=>" doesn't autoquote
what's on it's right.

People have grown to abuse this operator for all kinds of other
purposes, usually for "aesthetic" reasons; e.g. as a parameter separator
in a function call.

-- 
	Bart.


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

Date: Thu, 11 Nov 1999 08:54:08 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Perl and commonsense part 2
Message-Id: <MPG.1294948dd8046f1998a1dc@nntp.hpl.hp.com>

In article <382aea58.3820198@news.skynet.be> on Thu, 11 Nov 1999 
16:19:24 GMT, Bart Lateur <bart.lateur@skynet.be> says...

 ...

> People have grown to abuse this operator for all kinds of other
                       ^^
> purposes, usually for "aesthetic" reasons; e.g. as a parameter separator
> in a function call.

A polemic in two little letters.  s/ab//;

Also, s/"aesthetic" reasons/reasons of clarity/;

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 11 Nov 1999 14:44:23 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: Perl Extensions. Arrgh.
Message-Id: <bDAW3.2983$c06.25659@news.rdc1.ct.home.com>

Ilya Zakharevich <ilya@math.ohio-state.edu> wrote:
> [A complimentary Cc of this posting was sent to Dan Sugalski 
> <dan@tuatha.sidhe.org>],
> who wrote in article <AziW3.2915$c06.24415@news.rdc1.ct.home.com>:
>> > I noticed.  But my remark still stands: what do you think is the
>> > declaration of RETVAL?  It is C, not Perl, variables have types...
>> 
>> It's not C, it's XS. C with a heap of funky preprocessing done.

> My question was about the result of conversion to C.

The return's an SV. *All* returns from an XS module are ultimately SVs.

					Dan


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

Date: Thu, 11 Nov 1999 17:11:06 +0200
From: "Nimrod Shaulski" <nimi@sd.co.il>
Subject: Perl Interpreter in Java
Message-Id: <80em0d$bth$1@news.netvision.net.il>

Hi all.
I'm looking for a perl interpreter written on Java (so I can activate
scripts from inside my Java application).
Does anyone know something about it?
Thanks a lot.





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

Date: 11 Nov 1999 05:47:15 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: perl_call_method and method existance
Message-Id: <m166z9xhr0.fsf@halfdome.holdit.com>

>>>>> "Daniel" == Daniel Yacob <yacob@rcn.com> writes:

Daniel>   Is there a way to check if a method exists before calling it with
Daniel> "perl_call_method"?  I would like to not call the method and get warns
Daniel> if the user didn't provide the callback.

perldoc UNIVERSAL

examine "->can".

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


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

Date: Thu, 11 Nov 1999 14:52:02 GMT
From: Dan Sugalski <dan@tuatha.sidhe.org>
Subject: Re: perl_call_method and method existance
Message-Id: <mKAW3.2985$c06.25659@news.rdc1.ct.home.com>

Daniel Yacob <yacob@rcn.com> wrote:
> Greetings,

>   Is there a way to check if a method exists before calling it with
> "perl_call_method"?  I would like to not call the method and get warns
> if the user didn't provide the callback.

You can't do this too easily. Either just go ahead and call it with
the G_EVAL flag set to catch errors, or use gv_fetchmethod to get the GV
of the method. Using fetchmethod requires getting the HV * to the stash
for the package the object's been blessed into.

You can't just check the package stash for existence, of course, since
perl may walk up @ISA or call an AUTOLOAD for you somewhere along the
line.

					Dan


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

Date: Thu, 11 Nov 1999 22:03:45 +0800
From: "BY Wu" <biyong_wu@hotmail.com>
Subject: PHP problem
Message-Id: <80eibd$t12$1@newton.pacific.net.sg>

hi, I just installed php3 in my nt system with IIS3 server, now the problem
is I can run the php srcipt when I put the script under document root , I
can not run them form other dirctory. so I don't know wat is the problem ,
any one got this kind of problem . pls help me. thank you.




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

Date: Thu, 11 Nov 1999 06:13:29 -0800
From: Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Subject: Re: PHP problem
Message-Id: <004aa0e3.0ea77c9d@usw-ex0101-008.remarq.com>

In article <80eibd$t12$1@newton.pacific.net.sg>, "BY Wu"
<biyong_wu@hotmail.com> wrote:
> hi, I just installed php3 in my nt system with IIS3 server, now
> the problem
> is I can run the php srcipt when I put the script under document
> root , I
> can not run them form other dirctory. so I don't know wat is the
> problem ,
> any one got this kind of problem . pls help me. thank you.

And your perl problem is?

PHP3 is not perl, CGI is not perl, server-side scripting is not perl.

Your problem is likely to be related to server (IIS3) configuration or
permissions, I suspect. But this is not the place to have it addressed.

This is a perl newsgroup. Try asking in a PHP newsgroup and/or a http
server group.
--

Mark Bluemel



* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: 11 Nov 1999 14:37:25 GMT
From: simon@brecon.co.uk (Simon Cozens)
Subject: Re: PHP problem
Message-Id: <slrn82ll55.2np.simon@othersideofthe.earth.li>

BY Wu (comp.lang.perl.misc):
>hi, I just installed php3 in my nt system with IIS3 server, now the problem
>is I can run the php srcipt when I put the script under document root , I
>can not run them form other dirctory. so I don't know wat is the problem ,
>any one got this kind of problem . pls help me. thank you.

You seem to be in the wrong newsgroup. Perl isn't PHP.

-- 
"Out of register space (ugh)"
-- vi


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

Date: Thu, 11 Nov 1999 14:08:23 GMT
From: burt@ici.net (Burt lewis)
Subject: Removing leading zeros from a string?
Message-Id: <r5AW3.823$Hp1.52029@ndnws01.ne.mediaone.net>

Hello,

I know how to remove leading and trailing spaces ok
for ($string) {
            s/^\s+//;
            s/\s+$//;
        }

But I have a string that looks like this:
00000123456

And I need to remove the leading zeros up to the first non-zero
so it looks like this.
123456

I've spent way too much time trying to figure this out.

Appreciate any help.

Thanks!

Burt Lewis
burt@ici.net





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

Date: Thu, 11 Nov 1999 14:22:47 GMT
From: Vincent Murphy <vincent.murphy@cybertrust.gte.com>
Subject: Re: Removing leading zeros from a string?
Message-Id: <xjg9045cdl4.fsf@gamora.ndhm.gtegsc.com>

>>>>> "Burt" == Burt lewis <burt@ici.net> writes:

    Burt> Hello,
    Burt> I know how to remove leading and trailing spaces ok
    Burt> for ($string) {
    Burt>             s/^\s+//;
    Burt>             s/\s+$//;
    Burt>         }

    Burt> But I have a string that looks like this:
    Burt> 00000123456

instead of spaces you have zeroes. So:

perl -le "$num='0000012345'; ($num = $num) =~ s,^0+,,; print $num"

Beware that if $num = 0 the you will get nothing back.

    Burt> And I need to remove the leading zeros up to the first non-zero
    Burt> so it looks like this.
    Burt> 123456

    Burt> I've spent way too much time trying to figure this out.

You should look at perldoc perlre for more details.

--Vinny





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

Date: Thu, 11 Nov 1999 15:26:15 +0100
From: Alex Rhomberg <rhomberg@ife.ee.ethz.ch>
Subject: Re: Removing leading zeros from a string?
Message-Id: <382AD207.A9DD6B42@ife.ee.ethz.ch>

Burt lewis wrote:
> 
> Hello,
> 
> I know how to remove leading and trailing spaces ok
> for ($string) {
>             s/^\s+//;
>             s/\s+$//;
>         }
> 
> But I have a string that looks like this:
> 00000123456
> 
> And I need to remove the leading zeros up to the first non-zero

You can simply replace the \s (meaning whitespace) in the "remove
leading spaces" above woth 0:

s/^0+//;

But forcing numerical context is shorter:
$_+=0;  #removes leading zeroes

- Alex


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

Date: Thu, 11 Nov 1999 06:20:21 -0800
From: Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Subject: Re: Removing leading zeros from a string?
Message-Id: <0a0133f8.1071dbfd@usw-ex0101-008.remarq.com>

Taking my courage in both hands, I'll risk putting up some code to be
knocked down:-)

#!/usr/local/bin/perl -w
use strict;
my $x = "00000123456";
print "\$x is $x\n";
$x += 0;
print "\$x is $x\n";


HTH

--

Mark Bluemel


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Thu, 11 Nov 1999 06:42:34 -0800
From: Mark Bluemel <mark.bluemelNOmaSPAM@siemens.co.uk.invalid>
Subject: Re: Removing leading zeros from a string?
Message-Id: <2750ac20.163db168@usw-ex0101-008.remarq.com>

In article <382AD207.A9DD6B42@ife.ee.ethz.ch>, Alex Rhomberg
<rhomberg@ife.ee.ethz.ch> wrote:
[Snip]
> You can simply replace the \s (meaning whitespace) in the "remove
> leading spaces" above woth 0:
> s/^0+//;
> But forcing numerical context is shorter:
> $_+=0;  #removes leading zeroes

This was my answer too, and thinking about it, it almost qualifies as
"not a Perl question" - I remember doing this in INFO/BASIC (another
not-quite-interpreted, not strongly typed language) so decades ago, and
suspect it is pretty much an idiom in "typeless" languages.

--

Mark Bluemel


* Sent from RemarQ http://www.remarq.com The Internet's Discussion Network *
The fastest and easiest way to search and participate in Usenet - Free!



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

Date: Thu, 11 Nov 1999 15:36:49 GMT
From: rafala@my-deja.com
Subject: Re: Removing leading zeros from a string?
Message-Id: <80enqa$tl5$1@nnrp1.deja.com>

You just need a minor adjustment to what you
already have:

s/^0+//;

If you want to get rid of spaces and zeros at the
same time, it would look like this:

s/^[0\s]+//;

mike

In article <r5AW3.823
$Hp1.52029@ndnws01.ne.mediaone.net>,
  burt@ici.net (Burt lewis) wrote:
> Hello,
>
> I know how to remove leading and trailing
spaces ok
> for ($string) {
>             s/^\s+//;
>             s/\s+$//;
>         }
>
> But I have a string that looks like this:
> 00000123456
>
> And I need to remove the leading zeros up to
the first non-zero
> so it looks like this.
> 123456
>
> I've spent way too much time trying to figure
this out.
>
> Appreciate any help.
>
> Thanks!
>
> Burt Lewis
> burt@ici.net
>
>



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Thu, 11 Nov 1999 16:33:34 GMT
From: rafala@my-deja.com
Subject: substitution: $& equals replaced text
Message-Id: <80er4u$h3$1@nnrp1.deja.com>

We know that $& contains the recently matched text.
Is there a variable that contains the recent replacement text?

After a substitution, I need the best way to test whether the matched
text remains unchanged after a successful substitution.

This would be necessessary for complex patterns that use lots of
$scalers, optional wildcards (?), and alternation ( a|b ). That is,
when looking for many different variations of some text to be
standardized, sometimes you can't avoid matching the desired version of
the text.

A contrived example would be:

s/(S(mith)?)[\/\-\s]?(\sand|&)?\s?(J(ones)?)/[stuff]$1[otherstuff]$3
$4/g;

This matches:
Smith and Jones
Smith/Jones
S & J
S&Jones
etc.
etc.
etc.

And changes it to a complicated string that's determined by other
variables.

I'd like to be able to say:
if ($& eq $replacementtext) {...}

mike




Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: 11 Nov 1999 10:39:51 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: use overload -- "0+" takes the place of "bool"
Message-Id: <80e6dn$j5d$1@gellyfish.btinternet.com>

On Thu, 11 Nov 1999 16:38:06 +0800 John Lin wrote:
> 
> I think it is worthy revise the overloading behavior in this case.
> 

'Patches always welcome' ...

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
<http://www.gellyfish.com>
Hastings: <URL:http://dmoz.org/Regional/UK/England/East_Sussex/Hastings>


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

Date: 11 Nov 1999 14:49:31 GMT
From: goetz@cse.buffalo.edu (Phil Goetz)
Subject: Re: Virus
Message-Id: <80el1r$1lf$1@prometheus.acsu.buffalo.edu>

In article <x3ybt92yyqx.fsf@tigre.matrox.com>,
Ala Qumsieh  <aqumsieh@matrox.com> wrote:
>
>abigail@delanet.com (Abigail) writes:
>
>>                         unless ($program =~ /# HACKED/) {
>>                             $program =~ s/\n/\n$text/;
>>                         }
>
>Not a very smart virus. Very easy to fool. Just stick a '# HACKED'
>somewhere in the code.
>
>But a cool virus nevertheless.	
>
>--Ala

So nobody else on this newsgroup has a problem with people posting virii?
Plenty better things to work on and post.

Phil
flick@populus.net


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

Date: Thu, 11 Nov 1999 08:45:52 -0600
From: mpauser <mpauser@uswest.com>
Subject: Visual Package Manager (VPM)
Message-Id: <382AD6A0.B89A57A9@uswest.com>

Is there a way to get VPM without getting the whole PRK?

I'm not trying to warez,  I just need VPM without the rest of the PRK.

Thanks

***************************************************




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

Date: 11 Nov 1999 15:16:44 GMT
From: GiN@hookers.org (GiN)
Subject: Re: weird bugs?
Message-Id: <slrn82oca3.go.GiN@Avelon.net>

On Wed, 10 Nov 1999 18:43:22 GMT, Kragen Sitaker <kragen@dnaco.net> wrote:
>In article <slrn82kp70.7c.GiN@Avelon.net>, GiN <wablief@freemail.org> wrote:
>>2 examples:
>>
>>i opened a socket "S"
>>
>>print S "HEAD \/ HTTP\/1.0\n\n";       # http
>>and
>>print S ".\n";     # (e)smtp
>>
>>if i do this in C, it works.
>>but in perl it doesn't. i think the server couldn't get the "\n" so it
>>just waits
>>
>>who can tell me what i'm doing wrong?
>
>Are you autoflushing S?  use IO::Handle; autoflush S 1;
>-- 
><kragen@pobox.com>       Kragen Sitaker     <http://www.pobox.com/~kragen/>
>The Internet stock bubble didn't burst on 1999-11-08.  Hurrah!
><URL:http://www.pobox.com/~kragen/bubble.html>

yes thank you,

i forgot to autoflush the socket :)


-- 
Debian Linux -- Your next Linux distribution.
If you can't do it in Perl, you don't want to do it.



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

Date: Thu, 11 Nov 1999 07:11:48 -0800
From: Larry Rosler <lr@hpl.hp.com>
Subject: Re: Win32::Internet FTP List problem
Message-Id: <MPG.12947c91baf6968c98a1d9@nntp.hpl.hp.com>

[Posted and a courtesy copy sent.]

In article <80e168$it6$1@gellyfish.btinternet.com> on 11 Nov 1999 
09:10:32 -0000, Jonathan Stowe <gellyfish@gellyfish.com> says...
> On Wed, 10 Nov 1999 19:56:21 GMT Joris Lenior wrote:
> > I'm trying to write a perl script which downloads a set of files from
> > an HP3000 and converts them to excelsheets. Everything is working
> > except the FTP part. In the line @msfiles = $FTP->List("MS51*"), I try
> > to create an array containing the filenames I need. But instead of
> > having only the filenames, the array exists
> > of the following lines.
> > 239B  FA        4501      50000   1     4384  3 32  MS51R149
> > 239B  FA        3851      50000   1     4384  3 32  MS51R151
> > 239B  FA         165      50000   1     1472  1 32  MS51R152
> 
> @msfiles = map { (split / /)[8] } $FTP->List("MS51*");

  @msfiles = map { (split ' ')[8] } $FTP->List("MS51*");

There have been a few threads recently about not using apparent string 
literals for split() instead of regexes.  This is the exception.  :-)

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 1349
**************************************


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