[21703] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3907 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 3 06:05:40 2002

Date: Thu, 3 Oct 2002 03:05:11 -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           Thu, 3 Oct 2002     Volume: 10 Number: 3907

Today's topics:
    Re: Can I control "send_te" HTML compression header? <gisle@ashn89ty262h.bc.hsia.telus.net>
    Re: Convert Perl script to C program (and Why was this  <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Convert Perl script to C program (and Why was this  (Helgi Briem)
        Detecting Printers and/or Routers on a netwotk (win32) <a_hertz.ReMoVe@yahoo.com>
    Re: Entering a list with <STDIN> in DOS <andrew_harton@agilent.com>
    Re: Fuzzy text string match code needed <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: Help w map & its iterator plse <krahnj@acm.org>
    Re: How to geta list of perl modules news@roaima.freeserve.co.uk
    Re: Open File problem <nospam@nospam.com>
    Re: Perl Tutor Wanted - Mtn View, CA <nospam@nospam.com>
    Re: Perl Tutor Wanted - Mtn View, CA (M Browning)
    Re: POST slow with Netscape 4 and IIS? (Helgi Briem)
    Re: Printing text to a file <mike_constant@yahoo.com>
    Re: Question about srand <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: Script stops working when DBI added. Why? (Helgi Briem)
    Re: Sort hash of hash <smileface@libero.it>
    Re: Sort hash of hash <smileface@libero.it>
    Re: Sort hash of hash <bart.lateur@pandora.be>
    Re: Source-filename from diamond-operator <mike_constant@yahoo.com>
    Re: Source-filename from diamond-operator <joe@benburb.demon.co.uk>
        Splice function with arrays (patric)
    Re: Splice function with arrays <pinyaj@rpi.edu>
    Re: Splice function with arrays <mike_constant@yahoo.com>
    Re: Splice function with arrays <krahnj@acm.org>
    Re: Sticky forms without CGI.pm? <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
    Re: String substitution of 3+ digit numbers only? <bernard.el-hagin@DODGE_THISlido-tech.net>
    Re: Tricky question on calling a shell from a perl scri <mike_constant@yahoo.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 03 Oct 2002 08:30:00 GMT
From: Gisle Aas <gisle@ashn89ty262h.bc.hsia.telus.net>
Subject: Re: Can I control "send_te" HTML compression header?
Message-Id: <m31y77or72.fsf@ashn89ty262h.bc.hsia.telus.net>

joemercury@gmx.net (Joe) writes:

> I've just noticed that my Perl program sends a "TE: deflate" header.
> It wasn't here before. I believe it is because I installed compression
> library recently.

True.

> So where can I control the compression header TE: to set it ON or OFF?

This is a bit ugly, but should work:

   push(@LWP::Protocol::http::EXTRA_SOCK_OPTS, SendTE => 0);


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

Date: Thu, 3 Oct 2002 07:14:33 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <slrnapnrfv.142.bernard.el-hagin@gdndev25.lido-tech>

In article <g9Im9.276$3r2.2422851@newssvr21.news.prodigy.com>, .Fredo
wrote:
> 
> "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net> wrote in

[...]

>> Do you not understand the concept of a killfile? Neither Tad nor Alan
>> can see your replies, so why bother?
> 
> So they would have you think. It doesn't take a complete genius to
> figure out how to get around those. They need to be taught you just
> cannot "plonk" a person and hope that wins the argument. A killfile in
> it's self is not a bad thing, but the way it's commonly (mis)used to
> cheaply get the last word (especially if the plonker is wrong).


Your opinion on the use or misuse of killfiles has no bearing on the
fact that they didn't see your two replies to them.


> Over recent years, it has become a straight fact the Tad.


That sentence makes no sense.


> To deny what has been going on here for the past years is to deny history.


That is a statement which is *always* true no matter what you're
talking about. Think about it.


> No one, not even a revered book author, nor an expert programmer, has no
> right to display such rudeness when ever they see fit. This is what has
> been going on. I have been corresponding via email with various folk
> from this group for well over a year now, and this feeling not only felt
> by myself.


But what's forcing you to keep reading the group, then? Are you a
masochist?


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Thu, 03 Oct 2002 09:46:11 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Convert Perl script to C program (and Why was this group's name changed?)
Message-Id: <3d9c116f.2078347575@news.cis.dfn.de>

On Thu, 3 Oct 2002 07:14:33 +0000 (UTC), Bernard El-Hagin
<bernard.el-hagin@DODGE_THISlido-tech.net> wrote:

>> No one, not even a revered book author, nor an expert programmer, has no
>> right to display such rudeness when ever they see fit. This is what has
>> been going on. I have been corresponding via email with various folk
>> from this group for well over a year now, and this feeling not only felt
>> by myself.
>
>But what's forcing you to keep reading the group, then? Are you a
>masochist?

Ah, but you see, the lurkers support him in e-mail.

I think this is our "friend" Manny Wilco again, aka
Harl, Kamitri, Robin Givens, Al MacHonahey etc etc.
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Thu, 03 Oct 2002 08:13:58 +0200
From: Anders Hertz <a_hertz.ReMoVe@yahoo.com>
Subject: Detecting Printers and/or Routers on a netwotk (win32)
Message-Id: <1lnnpu83pi4jrv2sbkr659f7pilmm408bh@4ax.com>

Hiya

I'm making a little snooping program for our network as we are
currently switching around a lot of equipment.

So far it can figure out if it's an PC (and get info from it).

The basic part is quite simple. Ping the IP, If it answers check
if it is a PC if not then it's something unknown.

I'll like to narrow down the unknown part to tell if it's an printer
or a Network unit (not necesseraly the type, just it's a networking
unit).

Any ideas how to ?

Using Active Perl on Win2000.

/Anders, Denmark


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

Date: Thu, 3 Oct 2002 10:04:58 +0100
From: "Andrew Harton" <andrew_harton@agilent.com>
Subject: Re: Entering a list with <STDIN> in DOS
Message-Id: <1033635781.555005@cswreg.cos.agilent.com>

tu wrote:
> Hi,
> I am going through the exercises in the book "Learning Perl".  An
> number of exercise problems ask to write a program that reads a list
> of numbers (on separate lines) into an array variable.
>
> I know all I need to write in Perl is
> print "Enter the list you want to print.";
> @ArrayName = <STDIN>;
> print @ArrayName;
>
> My problem is when I run the script.  I get prompted to enter the
> list, but I don't know how to enter it in DOS.  I have tried entering
> list of numbers with a <return> after each number, and end with a
> CTRL-D.  All it does is print a dimond after the stuffs I entered.  I
> tried ending it with CTRL-Z, and it doesn't seem to work either.
>
> Please help.  -tt

CTRL-Z <return> on a line by itself should do the trick - works in W2K
anyway.

Andrew

--
$s="acehJklnoPrstu ";$_="4dbce078c32ae92a6e30152a";
split//;for(0..$#_){print substr($s,hex $_[$_],1);}




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

Date: Thu, 03 Oct 2002 08:35:27 +0200
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Fuzzy text string match code needed
Message-Id: <newscache$3n7e3h$sa8$1@news.emea.compuware.com>

Aaron D. Fuegi wrote (Tuesday 01 October 2002 21:01):

> I am wondering if anyone can direct me to code for doing fuzzy string
> matches of text strings.  Basically, I have a list of strings (game names
> in actuality) and, given another string, I want to know if it matches any
> of the existing strings, preferrably with some confidence percentage.  I
> would want it to handle things like:

Disregarding CPAN completey, I remember having read (a year ago?) an article 
on a Perl implementation for a fuzzy search tool. It was published in 
SysAdmin and my guess is the article is online on their website. If I 
remember correctly it dealt with searching for files with similar names.

[skip]

> Responses by email to aarondf@bu.edu preferred.

Well, in that case I will charge you EUR 75,= for an online consult.

HTH
-- 
KP



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

Date: Thu, 03 Oct 2002 07:06:22 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Help w map & its iterator plse
Message-Id: <3D9BEC4D.DBF0A6A3@acm.org>

Dick Penny wrote:
> 
> Here I go again, 3rd time in one day, you guys put up with a lot. Thanks.
> 
> I've successfully transformed an array of strings (actually from a file but
> not illustrated here) into an array of arrays containing strings(numbers)
> which I can access as a 2D matrix. Now I am trying to insert decimal points
> into all numbers whose string reprensation is 6 digits. My hang up (I think)
> is that I don't know how to use the 1st iterator $_ which is a ref to an
> annon array as input to a map.
> 
> Code follows, I desire @numbrs2 to be same size, shape, type, as @numbrs BUT
> with decimal points inserted into 6 digit strings, effectively scaling the
> data.
> 
> Can this all be done with a chain of maps?
> 
> _______ trial code, runs, but bad results
> use strict;
> use warnings;
> use Data::Dumper;
> my @lines = (
>    'SPH 083000  111200  111300  111100  111280   503   959',
>    'SPH 084000  111250  111380  111200  111370   354   115',
>    'SPH 084500  111350  111390  111050  111100   353   747' );
> my @numbrs = map{[/\d+/g]} @lines;
> my @numbrs2 =();
> print "numbrs are\n", Dumper @numbrs;
> foreach (@numbrs)
> {  @numbrs2 = map{[$_ =~ s/(\d{4})(\d{2})/$1\.$2/g]} @$_ }
> print "numbrs2 are\n", Dumper @numbrs2;


$ perl -le'
@lines = ( "SPH 083000  111200  111300  111100  111280   503   959",
           "SPH 084000  111250  111380  111200  111370   354   115",
           "SPH 084500  111350  111390  111050  111100   353   747"  );

@numbrs2 = map { [ map { s/(\d{4})(\d\d)$/${1}.$2/; $_ } /\d+/g ] } @lines;

print "@$_" for @numbrs2;
'
0830.00 1112.00 1113.00 1111.00 1112.80 503 959
0840.00 1112.50 1113.80 1112.00 1113.70 354 115
0845.00 1113.50 1113.90 1110.50 1111.00 353 747




John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 3 Oct 2002 10:33:42 +0100
From: news@roaima.freeserve.co.uk
Subject: Re: How to geta list of perl modules
Message-Id: <mt2hna.e8g.ln@moldev.cmagroup.co.uk>

In comp.lang.perl.misc Barry Kimelman <barryk2@delete_me.mts.net> asked:
> How do you get a list of modules that are installed on your system
> (UNIX or windows) ? I know you can use perldoc to get info on a
> specific module, but I need to get a list of ALL the installed modules.

If you have used CPAN to install them, you can get it to tell you:

    perl -MCPAN -e '
    	for $m (CPAN::Shell->expand("Module","/./")) {print $m->id,"\n"}
    '

Chris
-- 
@s=split(//,"Je,\nhn ersloak rcet thuarP");$k=$l=@s;for(;$k;$k--){$i=($i+1)%$l
until$s[$i];$c=$s[$i];print$c;undef$s[$i];$i=($i+(ord$c))%$l}


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

Date: Wed, 2 Oct 2002 23:26:58 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Open File problem
Message-Id: <3d9be2ab$1_2@nopics.sjc>


"kazchan" <kazchan@curio-city.com> wrote in message
news:3baaab4f.0210021731.2e9bdc09@posting.google.com...
> $id is generated by a simple put method form.  When someone submit a
> form with the specific numbers, the form should be mailed to the
> address specified in the data file.  Making a change from $exit to
> $next does not do anything different.

[snipped]
I assume you mean "exit" and "next".  Anyway, the change sure changes your
logic. With "next", you iterate thru the list of ID::email pairs to look for
a match. With "exit", you immediately stops the entire program with the
first non-match, but this might not be what you want because there might be
a match for subsequent entries.

As you said, you only had one valid $id which matched the first entry, but
subsequent submissions didn't give you a valid $id. You should check your
code where the $id is assigned. At the minimum, you shoud generate a list of
ids that you know exist in address.dat and run it thru your script to see if
you get it right (maybe case-sensitivity etc.)  Newer versions of Perl do
not require an & for a function invocation.

Something like this:

# You need to check if $id is defined
if (defined $id) {
    my ($line, $member, $mailto);
    open(FILEHANDLE,"<address.dat") or error("Could not open address.dat");
    while(chomp($line = <FILEHANDLE>)) {
         ($member,$mailto) = split(/::/, $line);
         last if (lc $id eq lc $member);
    }
    close FILEHANDLE;
    print "found $id\n" if (lc $id eq lc $member);
}
else {
    print "id is not defined\n";
}






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

Date: Wed, 2 Oct 2002 23:00:56 -0700
From: "Tan Nguyen" <nospam@nospam.com>
Subject: Re: Perl Tutor Wanted - Mtn View, CA
Message-Id: <3d9bdc92_3@nopics.sjc>

"Dick Penny" <penny1482@attbi.com> wrote in message
news:ygKm9.13753$Pz.14235@rwcrnsc51.ops.asp.att.net...
> Is there a real guru in Mtn View, CA area whose got 1-2 hrs once a week
for
> some Perl tutoring and Q's?  Initial subjects would be lists, arrays,
greps,
> maps, their implicit iterators, and building functional chains to
transform
> data. How much would you charge?
> --
> Dick Penny

Dick,

You can always register for a Perl class at a local JC. A few do offer good
Perl courses, and DeAnza is one of them. Good luck.




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

Date: 3 Oct 2002 01:11:14 -0700
From: m.browning@plymouth.ac.uk (M Browning)
Subject: Re: Perl Tutor Wanted - Mtn View, CA
Message-Id: <eddc4731.0210030011.3b10cb83@posting.google.com>

tadmc@augustmail.com (Tad McClellan) wrote in message news:<slrnapn6ua.4d2.tadmc@magna.augustmail.com>...
> Dick Penny <penny1482@attbi.com> wrote:
> 
> > IMHO perldoc sucks unless you know what Q to ask it
> 
> 
> I agree. I never actually _use_ the perldoc program, though
> I seem to cite it with the same frequency as drawing breath :-)
> 
> (I lied there. I do use perldoc for seeing _module_ documentation)
> 
> perldoc is a not-so-hot search tool though.
> 
> I find out where the *.pod files got installed and grep away
> to my heart's content.
> 
> If faced with information overload from too many hits, I make
> indexes and then grep the indexes. eg:
> 
>    grep ^=head perlfaq[0-9].pod >faq.indexed
> 
> Putting an Initial Cap on your search term is also a handy trick,
> finds it in titles and at the beginning of sentences.



I find:

$ perldoc -q searchterm

(query the FAQs) invaluable.  Users who find the CLI objectionable may
find Perldoc online helpful:

http://www.perldoc.com/

A comparable facility is installed locally as standard for users who
choose the ActiveState package.

[MB]


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

Date: Thu, 03 Oct 2002 09:04:59 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: POST slow with Netscape 4 and IIS?
Message-Id: <3d9c0741.2075741488@news.cis.dfn.de>

On Wed, 02 Oct 2002 22:48:29 +0100, Gerry Hickman
<gerry1@dircon.co.uk> wrote:

>> Where did you ask? In a Perl NG?
>
>This group.
>
>> Then it's no surprise that you didn't get any reply.
>> Your question/issue/problem has nothing to do with Perl whatsoever.
>
>I got plenty replies, but no one knew what was causing it.
>
>> You may want to ask in a NG that actually deals with
>> CGI/IIS/Apache/Win2k/HTML/TheWeb/Netscape/....
>
>Yup; I'll head over to cgi.iis.apache.win2k.html.theweb.netscape!! I
>know what you mean though. Part of the reason for asking on here is that
>lots of people use Perl with CGI, whereas most IIS people use .NET and
>ASP. I'm writing cross-platform so I'm stuck with CGI:(

Then, as you have been told before, try a newsgroup that 
deals with CGI.  Your problem is a CGI/web server issue,
not a Perl issue.  

Try comp.infosystems.www.authoring.cgi for CGI

ore of the following for web server configuration:

cmp.infosystems.www.servers.ms-windows
microsoft.public.inetserver.iis
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Wed, 2 Oct 2002 22:53:40 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Printing text to a file
Message-Id: <3d9bdade_5@nopics.sjc>


"Crackpot" <Crackhead@mensa.org> wrote in message

> Hello,
> I have a file that I create and I want to put text on it. However my text
> has tons of quotations and special characters. How do I print a block of
> text with special characters in Perl?

print q(what's up, dude?);

or

my $text =<<'EOT';
what's up, dude?
EOT

print $text;





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

Date: Thu, 03 Oct 2002 09:07:50 +0200
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Question about srand
Message-Id: <newscache$259e3h$7b8$1@news.emea.compuware.com>

Alan J. Flavell wrote (Tuesday 01 October 2002 18:39):

> On Oct 1, Koos Pol inscribed on the eternal scroll:
> 
>> >> David Britten wrote (Tuesday 01 October 2002 07:10):
>> >>
>> >>>                   ...   if I were to use srand to seed
>> >>> two different systems (i.e. different OS, architecture) with the same
>> >>> seed value, is there any chance that rand will generate the same
>> >>> sequence of numbers on those two systems?
> 
>> I don't understand what more you want to know besides:
>>        srand EXPR
>>        srand   Sets the random number seed for the "rand" opera-
>>                tor.  If EXPR is omitted, uses a semi-random value
>>                supplied by the kernel (if it supports the
>>            ->  /dev/urandom device) or based on the current time  <-
>>            ->  and process ID, among other things.                <-
> 
> 
> Hadn't you noticed that what you have quoted does not shed the
> slightest light on the hon Usenaut's original question?
> 
> He basically wants to know whether rand uses an architecture-
> independent algorithm.  In fact, the documentation doesn't answer that
> question directly, but I'm pretty sure the answer is "no".

My interpretation is that the OP wants to know how random random is. In that 
sense the manpage says everything. What I missed however is the need for a 
manua seed. And that could change everything indeed. My omission...

-- 
KP



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

Date: Thu, 03 Oct 2002 08:55:27 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Script stops working when DBI added. Why?
Message-Id: <3d9c053a.2075221751@news.cis.dfn.de>

On 2 Oct 2002 18:39:49 -0700, chopwood@resumemail.com (Chop
Wood) wrote:
> Just a question re Text Pad...hoping it works the same for 
>Windows as it does for Linux.
>
>I have Windows ME. I downloaded a Spanish doc into Text Pad probably 6
>mo ago now, and I believe Text Pad switched to Spanish mode at that
>time. I need to get it back into English but haven't a clue how to do
>it.

Your question is seriously off topic in this newgroup which
is about programming in Perl.

Try a group on text editors, for example comp.editors .

<off-topic>
Have you tried Configure - Preferences - Language?
</off-topic>
-- 
Regards, Helgi Briem
helgi AT decode DOT is

                           A: Top posting
                           Q: What is the most irritating thing on Usenet?
                                           - "Gordon" on apihna


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

Date: Thu, 03 Oct 2002 08:37:08 GMT
From: "Smileface" <smileface@libero.it>
Subject: Re: Sort hash of hash
Message-Id: <UkTm9.43080$e31.947227@twister2.libero.it>


"Janek Schleicher" <bigj@kamelfreund.de> wrote in message
news:3d9b38fe$0$11471$afc38c87@auth.de.news.easynet.net...
> Smileface wrote at Wed, 02 Oct 2002 17:26:10 +0200:
>
> > How can I sort an Hash of Hash by the final values?
> >
> > The hash is like this:
> >
> >   %HoH= (
> >                   'GGG' => { 'd' => 5 },
> >                   'AAA' => { 'a' => 8 },
> >                   'ZZZ' => { 'c' => 7 },
> >                   'DDD' => { 'b' => 6 },
> >                   'FFF' => { 'e' => 9 }
> >      );
> >
> > Thanks in advance,
>
> As Juergen already said, it's hard in the general case.
> If your data looks exactly like the above,
> you could try something:
>
> my @sorted_keys =
>    sort {(values %{$HoH{$a}})[0] <=> (values %{$HoH{$b}})[0]} keys %HoH;
>
> But it looks more like a mischoosen datastructure.
> Perhaps a hash of arrays is more appropriate ?

I'll try this solution , because I already know how to sort an Hash of List.
If neither this will be the right output, I'll transform the Hash in a
simplier one.

Thanks.





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

Date: Thu, 03 Oct 2002 09:17:52 GMT
From: "Smileface" <smileface@libero.it>
Subject: Re: Sort hash of hash
Message-Id: <4XTm9.43253$e31.949399@twister2.libero.it>


"Smileface" <smileface@libero.it> wrote in message
news:UkTm9.43080$e31.947227@twister2.libero.it...
>
> "Janek Schleicher" <bigj@kamelfreund.de> wrote in message
> news:3d9b38fe$0$11471$afc38c87@auth.de.news.easynet.net...
> > Smileface wrote at Wed, 02 Oct 2002 17:26:10 +0200:
> >
> > > How can I sort an Hash of Hash by the final values?
> > >
> > > The hash is like this:
> > >
> > >   %HoH= (
> > >                   'GGG' => { 'd' => 5 },
> > >                   'AAA' => { 'a' => 8 },
> > >                   'ZZZ' => { 'c' => 7 },
> > >                   'DDD' => { 'b' => 6 },
> > >                   'FFF' => { 'e' => 9 }
> > >      );
> > >
> > > Thanks in advance,
> >
> > As Juergen already said, it's hard in the general case.
> > If your data looks exactly like the above,
> > you could try something:
> >
> > my @sorted_keys =
> >    sort {(values %{$HoH{$a}})[0] <=> (values %{$HoH{$b}})[0]} keys %HoH;

SPECTACULAR!!!! It's run how I will!!
This is the only sintax I wasn't  tried, because I have it in mind but I
don't knew how to contruct it !!!!!

THANKS SO MUCH!!

> >
> > But it looks more like a mischoosen datastructure.
> > Perhaps a hash of arrays is more appropriate ?
>
> I'll try this solution , because I already know how to sort an Hash of
List.
> If neither this will be the right output, I'll transform the Hash in a
> simplier one.
>
> Thanks.
>
>
>




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

Date: Thu, 03 Oct 2002 09:18:37 GMT
From: Bart Lateur <bart.lateur@pandora.be>
Subject: Re: Sort hash of hash
Message-Id: <fq2opu43jiisiibb0k4op2bh2aa48p0va5@4ax.com>

Smileface wrote:

>> my @sorted_keys =
>>    sort {(values %{$HoH{$a}})[0] <=> (values %{$HoH{$b}})[0]} keys %HoH;
>>
>> But it looks more like a mischoosen datastructure.
>> Perhaps a hash of arrays is more appropriate ?
>
>I'll try this solution , because I already know how to sort an Hash of List.

For lots of data, this will be the slower solution.

-- 
	Bart.


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

Date: Wed, 2 Oct 2002 22:48:35 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Source-filename from diamond-operator
Message-Id: <3d9bd9ad$1_5@nopics.sjc>


"Fred" <No_Mail_Address@cox.net> wrote in message
news:3D9BD47D.C74230A@cox.net...
> I open a Perlscript vom the DOS-prompt (windows 98):
> Perl Myscript.pl sourcefile.txt
> then I open the sourcefile with the diamond operator:

>Question: How can I get the name of the sourcefile into a variable
> $source ?

 @ARGV or die "Need sourcefile \n";

my $source = $ARGV[0];
open(FH, $source) or die "open $source: $!\n";
while(<FH>) {
 ....
close FH




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

Date: 03 Oct 2002 07:42:35 +0000
From: joe mc cool <joe@benburb.demon.co.uk>
Subject: Re: Source-filename from diamond-operator
Message-Id: <u7it0k0xzo.fsf@benburb.tangent.com>

"Newbie" <mike_constant@yahoo.com> writes:

> >Question: How can I get the name of the sourcefile into a variable
> > $source ?
> 
>  @ARGV or die "Need sourcefile \n";
> 
> my $source = $ARGV[0];
> open(FH, $source) or die "open $source: $!\n";
> while(<FH>) {
>  ....
> close FH

Surely that is not really what he wants.

Rather:

	use strict;
	print "source filename = $0";

Joe




-- 
Joe Mc Cool
========================================================================
Tangent Computer Research BT71 7LN (www.tangent-research.com)
voice:(44)2837-548074fax:(44)-870-0520185 The more you say the less the better.


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

Date: 2 Oct 2002 22:24:58 -0700
From: patrick_cusack@hotmail.com (patric)
Subject: Splice function with arrays
Message-Id: <1ec975dc.0210022124.25ec554f@posting.google.com>

Say I wanted to flag a particular value in array ( like "5" in my
example). I find it and remove it via the splice function.  Why does
the for loop not catch the value again when the loop repeats? Any
comments would be appreciated.


@array = (1,2,3,4,5,5,6,7,8,9,10);

for ($i = 0;$i <= $#array; $i++){
  if ($array[$i] == 5){
     splice(@array,$i,1);
  }
}

print "\n@array\n";

results in:
BEFORE SPLICE 1 2 3 4 5 5 6 7 8 9 10
AFTER SPLICE  1 2 3 4 5 6 7 8 9 10


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

Date: Thu, 3 Oct 2002 01:40:15 -0400
From: Jeff 'japhy' Pinyan <pinyaj@rpi.edu>
To: patric <patrick_cusack@hotmail.com>
Subject: Re: Splice function with arrays
Message-Id: <Pine.SGI.3.96.1021003013737.11353A-100000@vcmr-64.server.rpi.edu>

[posted & mailed]

On 2 Oct 2002, patric wrote:

>Say I wanted to flag a particular value in array ( like "5" in my
>example). I find it and remove it via the splice function.  Why does
>the for loop not catch the value again when the loop repeats? Any
>comments would be appreciated.

I'll show you why.

>@array = (1,2,3,4,5,5,6,7,8,9,10);

The number '5' occurs at elements 4 and 5.

>for ($i = 0;$i <= $#array; $i++){
>  if ($array[$i] == 5){
>     splice(@array,$i,1);

The first time this happens, at $i = 4, all the elements past $array[$i]
get moved down one index.  This means that the ORIGINAL 5, at $array[4],
is removed, and the SECOND 5, at $array[5], is now at $array[4].  But the
loop then increments $i to 5.

>  }
>}

  for ($i = 0; $i < @array;) {
    if ($array[$i] == 5) { splice @array, $i, 1 }
    else { ++$i }
  }

Or better yet, use grep():

  @array = grep $_ != 5, @array;

-- 
Jeff "japhy" Pinyan      RPI Acacia Brother #734      2002 Acacia Senior Dean
"And I vos head of Gestapo for ten     | Michael Palin (as Heinrich Bimmler)
 years.  Ah!  Five years!  Nein!  No!  | in: The North Minehead Bye-Election
 Oh.  Was NOT head of Gestapo AT ALL!" | (Monty Python's Flying Circus)



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

Date: Wed, 2 Oct 2002 22:44:40 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Splice function with arrays
Message-Id: <3d9bd8c2$1_6@nopics.sjc>


"patric" <patrick_cusack@hotmail.com> wrote in

> Say I wanted to flag a particular value in array ( like "5" in my
> example). I find it and remove it via the splice function.  Why does
> the for loop not catch the value again when the loop repeats? Any
> comments would be appreciated.
>
>
> @array = (1,2,3,4,5,5,6,7,8,9,10);
>
> for ($i = 0;$i <= $#array; $i++){
>   if ($array[$i] == 5){
>      splice(@array,$i,1);
>   }
> }
>
> print "\n@array\n";

Because $i already incremented and the array has shrunk.
When you remove the first 5, the array shrinks to one element less than the
original size. Now, the second 5 is taking the place of the first 5 which is
already gone. When $i increments, the next position will contain the value
6.




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

Date: Thu, 03 Oct 2002 07:25:05 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Splice function with arrays
Message-Id: <3D9BF0AD.5D1C1D3C@acm.org>

patric wrote:
> 
> Say I wanted to flag a particular value in array ( like "5" in my
> example). I find it and remove it via the splice function.  Why does
> the for loop not catch the value again when the loop repeats? Any
> comments would be appreciated.
> 
> @array = (1,2,3,4,5,5,6,7,8,9,10);
> 
> for ($i = 0;$i <= $#array; $i++){
>   if ($array[$i] == 5){
>      splice(@array,$i,1);
>   }
> }
> 
> print "\n@array\n";
> 
> results in:
> BEFORE SPLICE 1 2 3 4 5 5 6 7 8 9 10
> AFTER SPLICE  1 2 3 4 5 6 7 8 9 10


As well as Jeff's fine explanation and example there are two other ways
to do it

# use redo
for ( my $i = 0; $i <= $#array; $i++ ) {
    if ( $array[$i] == 5 ) {
        splice @array, $i, 1;
        redo;
    }
}

# start at the other end of the array
for ( my $i = $#array; $i >= 0; $i-- ) {
    if ( $array[$i] == 5 ) {
        splice @array, $i, 1;
    }
}




John
-- 
use Perl;
program
fulfillment


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

Date: Thu, 03 Oct 2002 08:53:50 +0200
From: Koos Pol <koos_pol@NO.nl.JUNK.compuware.MAIL.com>
Subject: Re: Sticky forms without CGI.pm?
Message-Id: <newscache$qh8e3h$sa8$1@news.emea.compuware.com>

Garry wrote (Wednesday 02 October 2002 03:12):

> I loathe writing second-hand HMTL with CGI.pm but I need the sticky form
> feature. Any ideas how to do it without CGI.pm? Do I need to access
> $REQUEST_URI or $QUERY_STRING? Parse this with regex's?
> 
> Garry Heaton

There is the trivial solution: CGI::FormBuilder.
Forms are sticky and the module is very convenient and easy to use.
HTH
-- 
KP



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

Date: Thu, 3 Oct 2002 07:20:31 +0000 (UTC)
From: Bernard El-Hagin <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: String substitution of 3+ digit numbers only?
Message-Id: <slrnapnrr4.142.bernard.el-hagin@gdndev25.lido-tech>

In article <3d9b38f4$0$11471$afc38c87@auth.de.news.easynet.net>, Janek
Schleicher wrote:
> Stan Ng wrote at Wed, 02 Oct 2002 14:49:41 +0200:
> 
>> I need to do a string replacement for numbers with 3 or more digits:
>> 
>>     "Message 345245: Please give 27 dollars to Alice345 at 12:20"
>> 
>> to become
>> 
>>     "Message 3 4 5 2 4 5: Please give 27 dollars to Alice 3 4 5 at 12:20"
>> 
>> That is, numbers more than 2 digits long are blasted apart, but 2-digit
>> numbers are kept intact.
>> 
>> I need to do this in a single regexp substitution like
>> 
>>    str =~ s/{regexp1}/{regexp2}/g;
>> 
>> or perhaps several substutions. What can I use as regexp1 and regexp2 to 
>> get this to happen?
> 
> Here's yet another solution that has the advantage of being
> shorter than the other two ones :-)
> 
> s/(\d{3,})/$_=$1;s#(?=.)# #g;$_/ge;
> 
> It also has the disadvantage of being very cryptic and
> to overwrite the global variable $_.


That second disadvantage is easily fixed:


s/(\d{3,})/local $_=$1;s#(?=.)# #g;$_/ge;


It's still cryptic, though. And ugly, I might add. ;)


Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'


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

Date: Wed, 2 Oct 2002 22:57:19 -0700
From: "Newbie" <mike_constant@yahoo.com>
Subject: Re: Tricky question on calling a shell from a perl script
Message-Id: <3d9bdbb8$1_1@nopics.sjc>


"Zeus" <zeus_riposta@yahoo.com> wrote in message
news:3D9BB3AD.2804C034@yahoo.com...
> A correction: In the example below, S is a shell while A, B and C are
shell
> scripts. Please forgive me for not phrasing the question correctly.
>
> Zeus.
>
> Zeus wrote:
>
> > Hi,
> >
> > I'm trying to call a shell script from a perl script which should run a
> > few programs and then exit back to the perl script.
> >
> > For example, perl script P invokes shell script S to run programs A, B &
> > C. Then the unix equivalent of what I'm trying to achieve is:
> > cat << EOF | S
> > A
> > B
> > C
> > EOF
> >
> > In the above example, A, B & C will be executed within shell S and on
> > completion S exits back to the parent shell.
> >
> > I'd like to know whether this can be achieved in perl.
> >
> > Thanks,
> >
> > Zeus.
>

Sure you can do it with Perl. Shell scripts, afterall, are just processes.
Check out "system" , backtick, exec, qx etc.




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

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.  

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


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