[10607] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4199 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Nov 11 16:08:28 1998

Date: Wed, 11 Nov 98 13:01:31 -0800
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, 11 Nov 1998     Volume: 8 Number: 4199

Today's topics:
    Re: <<My Sort Problem>> <tchrist@mox.perl.com>
        Array question in Perl? shazad@my-dejanews.com
    Re: Array question in Perl? <Allan@due.net>
    Re: Array question in Perl? <jason.holland@dial.pipex.com>
    Re: calling by reference <jdporter@min.net>
    Re: calling by reference <r28629@email.sps.mot.com>
    Re: calling by reference (Jon Drukman)
    Re: calling by reference <baliga@synopsys.com>
    Re: Can A Perl/CGI Script prevent robots? (brian d foy)
    Re: Comparing Arrays -- infinite loop? <garethr@cre.canon.co.uk>
    Re: Decimal to Hex conversion (Paul Anderson)
        Finding overlapping patterns <ben@sophocles.gws.uky.edu>
    Re: Finding overlapping patterns <uri@sysarch.com>
    Re: Finding overlapping patterns (Sean McAfee)
    Re: Fun NYC job consulting/FT Perl/Tk/DBI/C++ jeans + T <jdporter@min.net>
    Re: Fun NYC job consulting/FT Perl/Tk/DBI/C++ jeans + T <uri@sysarch.com>
    Re: HELP , I just can figure this out <d-edwards@nospam.uchicago.edu>
    Re: help explain a regx example?! <uri@sysarch.com>
    Re: help explain a regx example?! (Jon Drukman)
        Help with a little prob in a soft. <lea@altern.org>
    Re: Help with Perl5 <delonad@netdoor.com>
    Re: help:counting the number of occurences of a specifi (Patrick Timmins)
    Re: How do I sort this list by "port" number? <r28629@email.sps.mot.com>
        hypermail files into text (Warren Dodge)
    Re: info on files <ludlow@us.ibm.com>
        Inserting Data in Line <gala@sonic.net>
        Percentages Part 2 <dixonmat@pouch.com>
        Perl,ActiveS,run? <forrest7@realtime.net>
        question about array naming <raphe.berry@sun.com>
    Re: question about array naming <jason.holland@dial.pipex.com>
        Regular expression questions (Dave Rathnow)
        Submitting binary data with post? <mohid@nortel.ca>
    Re: Submitting binary data with post? <jason.holland@dial.pipex.com>
        value not entered <ours@casema.net>
        Value of <HANDLE> construct can be "0"... <hove@ido.phys.ntnu.no>
        XQL (Gustaf Liljegren)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 11 Nov 1998 19:08:34 GMT
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: <<My Sort Problem>>
Message-Id: <72cnbi$jgk$1@csnews.cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, dccobb@yahoo.com writes:
:I appreciate you telling me that Perl does have a command for sorting.	

Well, *actually*.... Perl doesn't have `commands' any more than C++
does -- shells do.

--tom
-- 
Tactical?  TACTICAL!?!?  Hey, buddy, we went from kilotons to megatons
several minutes ago.  We don't need no stinkin' tactical nukes.
(By the way, do you have change for 10 million people?) --lwall


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

Date: Wed, 11 Nov 1998 19:15:29 GMT
From: shazad@my-dejanews.com
Subject: Array question in Perl?
Message-Id: <72cnog$5as$1@nnrp1.dejanews.com>

Hi all...

I have a file which has a one liner:

# /tmp/garbage
this is a test for my class today.

I then read my file into an array, @oneliner.  But the whole garbage file is
read into $oneline[0].   i need to run another array against this @oneliner
array, so that the FIRST MATCH between the two arrays should copy that match
into garbage file.

My problem is trying to resolve, so that @oneliner should display:
$oneliner[0]=this
$oneliner[1]=is
$oneliner[2]=a
-
-
-

The rest I can deal with...

sm

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 11 Nov 1998 15:43:31 -0500
From: "AmD" <Allan@due.net>
Subject: Re: Array question in Perl?
Message-Id: <72cstt$ism$1@camel18.mindspring.com>


shazad@my-dejanews.com wrote in message <72cnog$5as$1@nnrp1.dejanews.com>...
>Hi all...
>
>I have a file which has a one liner:
>
># /tmp/garbage
>this is a test for my class today.
>
>I then read my file into an array, @oneliner.  But the whole garbage file
is
>read into $oneline[0].   i need to run another array against this @oneliner
>array, so that the FIRST MATCH between the two arrays should copy that
match
>into garbage file.
>
>My problem is trying to resolve, so that @oneliner should display:
>$oneliner[0]=this
>$oneliner[1]=is
>$oneliner[2]=a
>-
>-

Well, one may might be:

#!/usr/local/bin/perl -w

open(TMP,'tmp') or die "A horrible death which was: $!";
while (<TMP>) {
    chomp;
    @oneliner = split;
}

close(TMP) or die "Forgotten and alone because: $!";

foreach (@oneliner) {
    print "Element[",$i++,"]: $_\n";
}

AmD





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

Date: Wed, 11 Nov 1998 20:42:51 +0000
From: Jason Holland <jason.holland@dial.pipex.com>
To: shazad@my-dejanews.com
Subject: Re: Array question in Perl?
Message-Id: <3649F6CB.F169E88F@dial.pipex.com>

shazad@my-dejanews.com wrote:
> 
> Hi all...
> 
> I have a file which has a one liner:
> 
> # /tmp/garbage
> this is a test for my class today.
> 
> I then read my file into an array, @oneliner.  But the whole garbage file is
> read into $oneline[0].   i need to run another array against this @oneliner
> array, so that the FIRST MATCH between the two arrays should copy that match
> into garbage file.
> 
> My problem is trying to resolve, so that @oneliner should display:
> $oneliner[0]=this
> $oneliner[1]=is
> $oneliner[2]=a

Hm, interesting...

Try:

	my $tmp = <FILE>;             # Slurp file
	chomp( $tmp );                # Dump line ending
	@online = split( / /, $tmp ); # Split on space


You can probably compress this into a oneliner.

Bye!

-- 
sub jasonHolland {
    my %hash = ( website =>
'http://dspace.dial.pipex.com/jason.holland/',
                 email   => 'jason.holland@dial.pipex.com' );
}


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

Date: Wed, 11 Nov 1998 14:16:04 -0500
From: John Porter <jdporter@min.net>
Subject: Re: calling by reference
Message-Id: <3649E274.A18E8A69@min.net>

Avshi Avital wrote:
> 
> the following sub expects a string and returns the last word:
> 
> sub get_word {
>     $_[0] =~ s/\b([^\s]*?)\s*$//;

Perl has a handy alias for [^\s] -- it's \S.


>     return $1;
> }
> 
> obviously it doesn't change the value of the input string (though it
> DOES change $_[0] - locally).

You're wrong, it DOES change the input string.

You have to remember that the elements @_ variable are ALIASES
of actual arguments, so changing $_[0] actually changes the first
argument passed in.

You would have noticed this right away if you had ever called get_word()
with a literal string; because in that case perl dies with the message:

	Modification of a read-only value attempted

And if you pass in a variable, you can check its value after the call,
and see that it has in fact been altered.


> what if I wanted it to change it's value (that is: return the last word,
> and shorten the input string by one word)?
> i suppose it's some use of reference (\)?

So since this is the behavior that you already have, let's see how
you'd get the other behavior -- NOT altering the input string.

How about, using m// to match instead of s/// to substitute?

  sub get_word_nondestructive {
    $_[0] =~ m/\b(\S*?)\s*$/ ? $1 : ()
  }

-- 
John "Throbblefoot" Porter

Please Don't "Courtesy CC" me.
I read this newsgroup fanatically.  You know that!
("Emailed only" is fine, though.)

"The people at the Grey Hotel
  Are either aged or unwell." -- EG


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

Date: Wed, 11 Nov 1998 13:25:16 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Avshi Avital <avitala@macs.biu.ac.il>
Subject: Re: calling by reference
Message-Id: <3649E49C.30168788@email.sps.mot.com>

[posted to comp.lang.perl.misc and copy emailed]

Avshi Avital wrote:
> 
> hi guys (and gals),
> the following sub excepts a string and returns the last word:
> 
> sub get_word {
>     $_[0] =~ s/\b([^\s]*?)\s*$//;
>     return $1;
> }
> 
> obviously it doesn't change the value of the input string (though it
> DOES change $_[0] - locally).
> what if I wanted it to change it's value (that is: return the last word,
> and shorten the input string by one word)?
> i suppose it's some use of reference (\)?

Have you tried it?

Although @_ is local to the subroutine, its values are infact aliased to
the actual scalar variables passed into the subroutine.

RTFM, perldoc perlsub

-tk


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

Date: 11 Nov 1998 19:52:29 GMT
From: jsd@hudsucker.gamespot.com (Jon Drukman)
Subject: Re: calling by reference
Message-Id: <slrn74jqpv.8qp.jsd@hudsucker.gamespot.com>

In article <72ch8j$mnm$1@cnn.cc.biu.ac.il>, Avshi Avital wrote:
>hi guys (and gals),
>the following sub excepts a string and returns the last word:
>
>sub get_word {
>    $_[0] =~ s/\b([^\s]*?)\s*$//;
>    return $1;
>}
>
>obviously it doesn't change the value of the input string (though it
>DOES change $_[0] - locally).

are you sure?  did you test it?  if not, why not?

>what if I wanted it to change it's value (that is: return the last word,
>and shorten the input string by one word)?
>i suppose it's some use of reference (\)?

nope.

i recommend another reading of 'perlsub':

       Any arguments passed to the routine come in as the array
       @_.  Thus if you called a function with two arguments,
       those would be stored in $_[0] and $_[1].  The array @_ is
       a local array, but its elements are aliases for the actual
       scalar parameters.  In particular, if an element $_[0] is
       updated, the corresponding argument is updated (or an
       error occurs if it is not updatable).

-- 
Jon Drukman                                            jsd@gamespot.com
-----------------------------------------------------------------------
Fear the government that fears your computer.


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

Date: Wed, 11 Nov 1998 12:16:37 -0800
From: Yogish Baliga <baliga@synopsys.com>
To: Avshi Avital <avitala@macs.biu.ac.il>
Subject: Re: calling by reference
Message-Id: <3649F0A5.D14D3C05@synopsys.com>

#!/usr/local/bin/perl5.003 -w

my $text="My Name";

getLastWord( \$text );

print "text =$text:\n";

sub getLastWord {
   my $refText = shift;

   ${$refText} =~ s/\s*\b[^\s]+\b$//g;
}


Avshi Avital wrote:

> hi guys (and gals),
> the following sub excepts a string and returns the last word:
>
> sub get_word {
>     $_[0] =~ s/\b([^\s]*?)\s*$//;
>     return $1;
> }
>
> obviously it doesn't change the value of the input string (though it
> DOES change $_[0] - locally).
> what if I wanted it to change it's value (that is: return the last word,
> and shorten the input string by one word)?
> i suppose it's some use of reference (\)?
>
> thanx for any help!
> --
> Avshalom Avital
> Information Retrieval Laboratory
> Bar-Ilan University, Israel
> avitala@macs.biu.ac.il



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

Date: Wed, 11 Nov 1998 14:43:39 -0500
From: comdog@computerdog.com (brian d foy)
Subject: Re: Can A Perl/CGI Script prevent robots?
Message-Id: <comdog-ya02408000R1111981443390001@news.panix.com>

In article <01be0d7c$77147dd0$2611cfa8@oh02burtdj>, "Burt, David J" <david.burt@worldnet.att.net> posted:

> I would recomend making the areas of the site that you don't want the robot
> to go a user interactive condition.

robots can easily pretend to be users.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>


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

Date: Wed, 11 Nov 1998 19:15:22 GMT
From: Gareth Rees <garethr@cre.canon.co.uk>
Subject: Re: Comparing Arrays -- infinite loop?
Message-Id: <sipvauxcqd.fsf@cre.canon.co.uk>

Oliver Moffat <xcom2@popserver.panix.com> wrote:
> I'm trying to write a Perl script to automate the updating of a flat
> text file database. I'm trying to compare the new database of titles
> to the old databse of titles and get a list of "Brand New Titles."

Section 4.7 of the "Perl Cookbook" by Tom Christiansen and Nathan
Torkington is called "Finding Elements in One Array but Not Another",
and provides the following recipe:

  # Compare arrays @A and @B

  # Build lookup table to test membership of @B
  %seen;
  @seen{@B} = ();

  # Find elements in @A but not in @B
  @Aonly;
  foreach $item (@A) {
    push @Aonly, $item unless exists $seen{$item};
  }

(Posted and e-mailed)

-- 
Gareth Rees


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

Date: Wed, 11 Nov 1998 14:17:06 GMT
From: paul@dcs.ed.ac.uk (Paul Anderson)
To: ehagen@Hawaii.Edu (Eric Hagen)
Subject: Re: Decimal to Hex conversion
Message-Id: <F29H0J.Fo7.0.staffin.dcs.ed.ac.uk@dcs.ed.ac.uk>

In article <71qbl4$6a0@news.Hawaii.Edu>,
 ehagen@Hawaii.Edu (Eric Hagen) writes:
> 
> I have found hex () to convert from hex to decimal, and printf to print
> out hex values, but for the life of me I can not find in any of my docs on
> how to covert decimal values to hex values.  

Is this what you want?

	$hex = sprintf "%x", $dec;

-- 
Paul Anderson <mailto:paul@dcs.ed.ac.uk>    Phone: (+44) (0)131-650-5193
Division of Informatics,  JCMB,  University of Edinburgh,   EH9 3JZ,  UK
<http://www.dcs.ed.ac.uk/~paul/> (PGP Key)    Fax: (+44) (0)131-650-5193
PGP DSS: 1024/C635DAA2 2B8B 79AD DD40 6062 BDD1 7927 F241 8077 C635 DAA2


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

Date: Wed, 11 Nov 1998 14:10:15 -0500
From: Benjamin Stapley <ben@sophocles.gws.uky.edu>
Subject: Finding overlapping patterns
Message-Id: <3649E117.AB376105@sophocles.gws.uky.edu>

Probably a very simple question.

I am trying to extract all occurrences of a particular pattern from a string.

Some of which may overlap: e.g..

  extract all occurrences of the regex /P??P/ from "AAPPBPPAA"

I actually want to place all the substrings that match this pattern in a new array.

I got this far.

s/P??P/push(@PXXP,$&)/ge ;

How can I extend this to match overlapping occurrences?

(I am a biologist, so be patient.)

Thanks

Ben





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

Date: 11 Nov 1998 14:36:35 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Finding overlapping patterns
Message-Id: <x7g1bq9g3g.fsf@sysarch.com>

>>>>> "BS" == Benjamin Stapley <ben@sophocles.gws.uky.edu> writes:

  BS> Probably a very simple question.  I am trying to extract all
  BS> occurrences of a particular pattern from a string.
  BS> Some of which may overlap: e.g..

  BS>   extract all occurrences of the regex /P??P/ from "AAPPBPPAA"

  BS> I got this far.
  BS> s/P??P/push(@PXXP,$&)/ge ;

this isn't too far. it actually only matches a single P. you have perl
regexex confused with shell file globbing. in shells ? is a single
char. in perl ? is either a quantifier (0 or 1 occurance) or the
non-greedy modifier. in this case you selected 0 or 1 P and the shortest
match of that which is 0 P's. then match a single P.

  BS> How can I extend this to match overlapping occurrences?

  BS> (I am a biologist, so be patient.)

i am trying. :-)

some of this has been discussed recently in a thread that was about
getting all substrings of a match.

here is a loose algorithm (which may be beyond your perl skills now).

use the pos() function to set the starting match location in the
string. when you get a match, increment the existing match pos by 1.

if your match string is fixed length, this will work. if it is variable
length then the question is what is a match?

in 'AAPAPPSP' there are these matches to /P.*P/ of all possible lengths

PAP
PAPP
PAPPSP
PP
PPSP
PSP

AFAIK no single regex can get all of those matches.

this might be simpler to do with index and 2 loops. the outer loop
indexes for the first P and the inner loop for the second P. on failure,
exit the loop.  each loop looks for the next P. use substr to extract
the strings.

here is a working example:

$line = 'AAPAPPSP' ;

$first_p = 0 ;

while( ( $first_p = index( $line, 'P', $first_p ) ) > 0 ) {

	$second_p = $first_p + 1;

	while( ( $second_p = index( $line, 'P', $second_p ) ) > 0 ) {

		print substr( $line, $first_p, $second_p - $first_p + 1 ), "\n";

		$second_p++ ;
	}

	$first_p++ ;
}

this prints:
PAP
PAPP
PAPPSP
PP
PPSP
PSP

you have to define what you want more carefully to get a proper
algorithm that will do what you want.

and read perlre and "mastering regular expressions" by friedl to leanr
more about this fascinating area.

hth,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Wed, 11 Nov 1998 19:43:45 GMT
From: mcafee@waits.facilities.med.umich.edu (Sean McAfee)
Subject: Re: Finding overlapping patterns
Message-Id: <RNl22.6189$fS.20360925@news.itd.umich.edu>

In article <3649E117.AB376105@sophocles.gws.uky.edu>,
Benjamin Stapley  <ben@sophocles.gws.uky.edu> wrote:
>I am trying to extract all occurrences of a particular pattern from a string.
>Some of which may overlap: e.g..
>  extract all occurrences of the regex /P??P/ from "AAPPBPPAA"

Do you want a pattern which matches a P, followed by any two characters,
then another P?  If so, the pattern you really want is /P..P/.  /P??P/
means "Zero or one P's, whichever is lesser, followed by another P".
This is exactly equivalent to matching one single P.  See the perlre
manpage for information about the ?? quantifier.

>I actually want to place all the substrings that match this pattern in a new array.
>I got this far.
>s/P??P/push(@PXXP,$&)/ge ;

I don't think you want to do a global substitute like that, as it will
destroy the contents of the original string.  Assuming I'm correct about
your true goal, this would be the more correct way to do the above:

push(@PXXP, $&) while $mystring =~ /P..P/g;

It's almost always better to avoid using $&, so do this instead:

push(@PXXP, $1) while $mystring =~ /(P..P)/g;

>How can I extend this to match overlapping occurrences?

By using regex constructs that don't consume what they match: lookahead
assertions.  I refer you again to the perlre manpage, but here's how it
might be done:

push(@PXXP, $1) while $mystring =~ /(?=(P..P))/g;

Or even:

push(@PXXP, $mystring =~ /(?=(P..P))/g);

-- 
Sean McAfee | GS d->-- s+++: a26 C++ US+++$ P+++ L++ E- W+ N++ |
            | K w--- O? M V-- PS+ PE Y+ PGP?>++ t+() 5++ X+ R+ | mcafee@
            | tv+ b++ DI++ D+ G e++>++++ h- r y+>++**          | umich.edu


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

Date: Wed, 11 Nov 1998 14:06:52 -0500
From: John Porter <jdporter@min.net>
Subject: Re: Fun NYC job consulting/FT Perl/Tk/DBI/C++ jeans + Tshift
Message-Id: <3649E04C.5EE82040@min.net>

Brian Saltzman wrote:
> 
> ... there seems to be few people
> who have unix experience and want to work with PC software. 

Surprise, surprise.

Few roofers who have used pneumatic nail guns want to go back
to using hammers.

John Porter


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

Date: 11 Nov 1998 14:10:35 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Fun NYC job consulting/FT Perl/Tk/DBI/C++ jeans + Tshift
Message-Id: <x7iugm9has.fsf@sysarch.com>

>>>>> "JP" == John Porter <jdporter@min.net> writes:

  JP> Brian Saltzman wrote:
  >> 
  >> ... there seems to be few people
  >> who have unix experience and want to work with PC software. 

  JP> Surprise, surprise.

  JP> Few roofers who have used pneumatic nail guns want to go back
  JP> to using hammers.

i'd like to use either tool on winblows. repeatedly. and maybe on uncle
bill too. :-)

let's root for the DOJ! you can't root for u$hit since they don't
support root.

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Wed, 11 Nov 1998 18:57:40 GMT
From: Darrin Edwards <d-edwards@nospam.uchicago.edu>
Subject: Re: HELP , I just can figure this out
Message-Id: <tgd86ut5uj.fsf@noise.bsd.uchicago.edu>

Tom Phoenix <rootbeer@teleport.com> writes:

> On Tue, 10 Nov 1998, Darrin Edwards wrote:
> 
> > > > $CMD->Parameters("lname")->{value}=$linesin{$lname};
> 
> > If the value of "exists($linesin{$lname})" were false, couldn't
> > that also have produced the "Use of uninitialized value at..." error?
								   ^^^^^
(my bad, this should have been "warning")

> Well, it would mean that the statement would be trying to assign a value
> of undef, but that's not going to trigger a warning. That particular
> warning that you're talking about should happen only with actual _use_ of
> the value in an expression, where the undef needs to be converted to
> either '' or 0. And, at that, Perl should recognize several legitimate
> uses for undefined (values from) variables, and not complain.

Hmm, perl -w has always given me that warning whenever I've tried
to use a key that didn't "exist" yet in a hash:

noise:~>perl -we 'my %Marge; my $Homer = "Mmm"; $Homer = $Marge{lisa};
		print $Homer, "\n";'  
Use of uninitialized value at -e line 1.

But anyway, it was pretty clear that the original poster was getting
multiple errors from that line...

Darrin


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

Date: 11 Nov 1998 14:06:06 -0500
From: Uri Guttman <uri@sysarch.com>
Subject: Re: help explain a regx example?!
Message-Id: <x7lnli9hi9.fsf@sysarch.com>

>>>>> "DB" == Dan Baker <dtbaker-@busprod.com> writes:

have you tried to look up the functions and regex features you don't
understand? you found the meanings of the /gsex modifiers so why not the
? modifier?

also please format your posts better. it is not only hard to read but
even harder to comment upon.

  DB> 	$text =~ s{ %% ( .*? ) %% } # put a matched quoted word into $1,
  DB> 				# but, in the "( .*? )" why is the ? there?

? is the non-greedy quantifier modifier (say that 5 times fast). it keep
the .* match as short as possible given the other regex requirements.

  DB> 	 { exists( $fillings->{$1} )   # this expression is killing me...
  DB> 	  ? $fillings->{$1}	# what is the significance of using curly {$1}?
  DB> 	  : ""			# and what is the exists()?: doing?

  DB> 	  }gsex;		# g=global, s=treat as single line, 
  DB> 				# e=causes second part to eval as expression 
  DB> 			# rather than string, x=allows whitespace in expression 

exists checks it an entry exists (nice name, huh?) in a hash. if you use
an undefined values in some expressions with the -w flag, you get
warnings. the code is just making sure the substituted value is defined.

the {$1} is indexing into the hash ref $fillings (which was filled by
code run earlier). the whole s/// operation replaces marked keywords (with
%% %%) with their actual values looked up in a hash. if the keyword
doesn't exist (that name again) in the hash, it is replaced by "" (which
should be '' IMO).


why did you quote the entire snippet from the cookbook? your previous
quote is enough to illuminate your quandry.

  DB> # If you would like to reply-to directly, remove the - from my username
  DB> * no spam please... regulated by US Code Title 47, Sec.227(a)(2)(B)  *

no reply either.

hth,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
Perl Hacker for Hire  ----------------------  Perl, Internet, UNIX Consulting
uri@sysarch.com  ------------------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: 11 Nov 1998 20:07:15 GMT
From: jsd@hudsucker.gamespot.com (Jon Drukman)
Subject: Re: help explain a regx example?!
Message-Id: <slrn74jrll.8qp.jsd@hudsucker.gamespot.com>

First off, get yourself a copy of Mastering Regular Expressions
by Jeffrey Friedl.  You won't regret it.

In article <3649DB95.A7B3B71A@busprod.com>, Dan Baker wrote:
>here is the section I need help with:
>
>	# replace quoted words with value in %$fillings hash
>	$text =~ s{ %% ( .*? ) %% }		# put a matched quoted word into $1, 
>						# but, in the "( .*? )" why is the ? there?

the ? limits the scope of the * so that it doesn't eat
every character up until the final %% in the string.

>		  { exists( $fillings->{$1} )	# this expression is killing me...
>			  ? $fillings->{$1}	# what is the significance of using curly {$1}?
>			  : ""			# and what is the exists()?: doing?

ok, two things here... the "conditional operator" (sometimes
called the ternary operator) which looks like:

expression ? true case : false case

is described in the perlop manpage.  It basically evalutes
the initial expression and if it's true, it returns the
true case, otherwise the false case.  Very useful.

So, in english, this says:  If there exists an element
of the %fillings hash whose key is $1, then give me the
value from the hash, otherwise give me the empty string "".

The curlies are because you're not really looking directly
at %fillings, you're looking at a reference to it.  This could
have been written as $$fillings{$1} instead but the -> dereference
operator is visually cleaner, I think.

The perl manpages you need to read are:

perlre - for regular expressions
perlop - for operators (like ?:)
perlref - for references

-- 
Jon Drukman                                            jsd@gamespot.com
-----------------------------------------------------------------------
Fear the government that fears your computer.


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

Date: Wed, 11 Nov 1998 21:29:42 +0100
From: Christine NICOLAS <lea@altern.org>
Subject: Help with a little prob in a soft.
Message-Id: <3649F3B6.A5B43631@altern.org>

This is a multi-part message in MIME format.
--------------FB310E782DBE778F8EDEEA0D
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Hello,

	 I Would like to change the soft wich is attached to the message, I
woulk like to answer at the end of the softare at the user if  he want
to run again the software, if yes, run again the software, if no, stop
the software.

	I would like to know if Unicode is comptabile with Perl.

	Thanks for your help,

	answer mailto:fred@freudian.com 

	Frederic FAUCOUNEAU
--------------FB310E782DBE778F8EDEEA0D
Content-Type: application/x-perl; name="anpe.pl"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="anpe.pl"

#!/usr/bin/perl 
print "Traduction du fichier Partenet\n";
print "Fred. FAUCOUNEAU Createur <fred.freudian.com>\n";
print "Entrez le nom du fichier a traiter:";
	$entree =<STDIN>; 
	chop($entree);
print "Entrez le nom du fichier de sortie:";
	$sortie =<STDIN>; 
	chop($sortie);
open (FILE,$entree) or die ("Impossible de trouver le fichier, vous avez du vous tromper : $!");
open (FLUTE,">$sortie") or die ("Oups,probleme :$!");

while (<FILE>) {
   chomp;                           #Demarrage des recherches des strings
   $offre=$1 if /(Offre.*?X)/;
   $date=$1 if /(Date.*?98)/;
   $Ale=$1 if  /(Ale.*?TD)/;
   $duree=$1 if /(Recherche.*?FONT>)/;
   $descriptif= $1 if /(R><FO.*?FONT>)/;
   $lieu=$1 if /(Lieu.*?FONT>)/;
   if (/(B>H.*?FONT)/) {            # On est a la fin du record"
      $horaires =$1;
#Zoup, on demarre l'impression dans le fichier 
print FLUTE "<HTML>";
print FLUTE "<BODY>" ;
print FLUTE "&nbsp;";
print FLUTE "<TABLE BORDER COLS=1>";
print FLUTE "<TR>";
print FLUTE "<TD><FONT SIZE=1><PRE><B>$offre					<B>$date				<B>$Ale</PRE></FONT>";
print FLUTE "<BR><FONT SIZE=1><B>$duree&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp";
print FLUTE "<CENTE$descriptif</CENTER>";
print FLUTE "<FONT SIZE=1><B><PRE>$lieu                                 			      <$horaires></PRE></TD>";
print FLUTE "</TR>";
print FLUTE "</TABLE>";
print FLUTE "</BODY>";
print FLUTE "</HTML>";

   }
}
print "Operation effectuee\n";
print "Le fichier a ete enregistre\n";
print "sous $sortie \n";

--------------FB310E782DBE778F8EDEEA0D--




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

Date: Wed, 11 Nov 1998 13:03:13 -0600
From: Aaron Delong <delonad@netdoor.com>
Subject: Re: Help with Perl5
Message-Id: <Pine.GSO.4.05.9811111302480.74-100000@lance.netdoor.com>

Try the following link...see if it has any answers to your question:

http://www.whitecrow.demon.co.uk/steve/iis4.html

On Wed, 11 Nov 1998, Carlos Woodcock wrote:

> hi,
> 
> i installed Perl5 and now whem i try to run a .pl on my browser it gives me
> this error:
> ----------------------------------------------------------
> HTTP Error 405
> 405 Method Not Allowed
> 
> The method specified in the Request Line is not allowed for the resource
> identified by the request. Please ensure that you have the proper MIME type
> set up for the resource you are requesting.
> 
> Please contact the server's administrator if this problem persists.
> ----------------------------------------------------------------------------
> --------
> 
> I have Nt40 server , IIS, and its a Alpha.
> 
> 
> 
> can anyone help me to correct this problem ?
> 
> check the URL to see the error:
> http://www.instituto-europeu.com/efff/curso.htm
> 
> thx
> 
> carl@mail.ineti.pt
> 
> 
> 
> 
> 



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

Date: Wed, 11 Nov 1998 18:46:53 GMT
From: ptimmins@netserv.unmc.edu (Patrick Timmins)
Subject: Re: help:counting the number of occurences of a specified string in a file
Message-Id: <72cm2t$3u8$1@nnrp1.dejanews.com>

In article <F2979A.616@liverpool.ac.uk>,
  bjjgann@liv.ac.uk wrote:

> I am trying to count the number of times a string appears
> in a given file.
>
> So far I have managed to count the number of occurences on a particular line,
> the number of the line where the string occurs, and just about any other
> combination you care to imagine, except for the result I want.
>
> Is this an easy 3 liner, which am just missing or is it more complex.
> Any advice would be appreciated.

$search = "whatever";
undef $/;
while (<>) { $count = s/$search//g; } # feed the file to the loop

$count will hold the number of times "whatever" was encountered
in the file you fed your script at the command line. You can add
\b boundaries or i modifiers to the regex to suit your needs. Reset
$/ when your finished, if you need to.

Patrick Timmins
$monger{Omaha}[0]

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Wed, 11 Nov 1998 12:49:43 -0600
From: Tk Soh <r28629@email.sps.mot.com>
To: Larry Rosler <lr@hpl.hp.com>
Subject: Re: How do I sort this list by "port" number?
Message-Id: <3649DC47.FA3AC0D4@email.sps.mot.com>

[posted to comp.lang.perl.misc and copy emailed]

Larry Rosler wrote:
> 
> [Posted to comp.lang.perl.misc and copy mailed.]
> 
> In article <O6822.6038$fS.19967516@news.itd.umich.edu> on Wed, 11 Nov
> 1998 04:10:22 GMT, Sean McAfee <mcafee@waits.facilities.med.umich.edu>
> says...
> > In article <72avp0$n0j$1@nnrp1.dejanews.com>,  <munn@bigfoot.com> wrote:
> ...
> > >25 Simple Mail Transfer tcp 101.1.48.26 101.1.49.36 Nov 6 00:04:33
> > >25 Simple Mail Transfer tcp 198.108.149.2 200.36.131.36 Nov 6 00:04:33
> > >25 Simple Mail Transfer tcp 198.108.149.2 198.81.17.2 Nov 6 00:04:33
> > >43424 not assigned tcp 198.108.149.2 207.82.90.10 Nov 6 00:04:33
> > >43235 not assigned tcp 198.108.149.2 203.18.38.243 Nov 6 00:04:33
> > >123 Network Time Protocol udp 101.1.48.26 101.1.48.67 Nov 6 00:04:33
> > [etc, snip]

[...]

> > @sorted_a = sort { $a <=> $b } @a;
> >
> > This is the same way one sorts lists of numbers, and it works here becasue
> > when each line is treated as a number, it turns into your port number.
> 
> But these are not lists of numbers.  They are strings that begin with
> numbers.

It looks fine to me here, since the <=> operator converts the string
(begin with numbers) into numbers before making comparison.  

  DB<38> X s
@s = (
   0  '6 aaa'
   1  '3 bbb'
   2  '9 xyz'
   3  'aaa'
)
  DB<39> @ss = sort @s

  DB<40> X ss
@ss = (
   0  '3 bbb'
   1  '6 aaa'
   2  '9 xyz'
   3  'aaa'
)
  DB<41> @ss = sort {$a<=>$b} @s

  DB<42> X ss
@ss = (
   0  'aaa'
   1  '3 bbb'
   2  '6 aaa'
   3  '9 xyz'
)

-tk


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

Date: 11 Nov 1998 19:08:18 GMT
From: warrend@sptekwv3.vnd.tek.com (Warren Dodge)
Subject: hypermail files into text
Message-Id: <72cnb2$msd$1@bvadm.wv.tek.com>

Is there a package available that can take a hypermail'ed mail message
and extract the text from all the HTML information.

I assume any HTML to TEXT package would work for this.

EMAIL replys would be best. Remove #_junk when replying.


-- 
 Warren Dodge,    Electronic Engineer              phone - (503) 627-4888
 Tektronix, Inc., VIDEO/NETWORKING Division (VND)  fax   - (503) 627-1231
 M/S 58-625, P.O. Box 500, 14180 SW. Karl Braun Drive  Beaverton, OR 97077-0001
 Email - warren.dodge@TEK.COM


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

Date: Wed, 11 Nov 1998 13:31:52 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: info on files
Message-Id: <3649E628.9F830917@us.ibm.com>

meehanc@my-dejanews.com wrote:
> 
> Hi,
>         I was wondering if there`s a way to display just the file
>         attributes of a list of files in Perl. for example, run a
>         perl script passing it a list of files, and perl would then
>         print out  <filename> has the following permissions -rwx---r-x
>         or whatever is relevant. I thought it could be done with stat

#!/usr/bin/perl -w
foreach (@ARGV) {
    print "$_ has permissions ", (split /\s+/, `ls -ld $_`)[0], "\n";
} 

Not terribly efficient, but it should work.  Of course, only use this
with a trusted list of filenames, since names like ';rm *' could be bad.

-- 
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)


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

Date: Wed, 11 Nov 1998 11:35:20 -0800
From: "Gala Grant" <gala@sonic.net>
Subject: Inserting Data in Line
Message-Id: <72corn$2ef$1@ultra.sonic.net>

I am trying to edit some HTML code with a perl scripts.  the problem is that
I need to insert a string into a string.  At first this may seem easy, but
the code is layed out different on each page.

<img src="../images/b2_feedb.gif"
    border="0"
<img src="../images/b2_gloss.gif" border="0"

and some are even two entries on the same line. I want to add text after the
 .gif".  Any ideas?
Gala Grant
gala@sonic.net

P.S.  No i didn't write the messy code in the first place.  I am trying to
fix someone elses mistake.




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

Date: Wed, 11 Nov 1998 20:58:03 GMT
From: "News" <dixonmat@pouch.com>
Subject: Percentages Part 2
Message-Id: <vTm22.117$5v3.875002@news.optonline.net>

ok so now on my script I got the percentage from this line.

if ($gtot >= 1000) { $gtot *= .25; }
   $gtot = &Monify ($gtot);
   print "<Td bgColor=\"#$tdBg1\" Align=left><b><Font Color=black>Discount
Rate</font></b><Td bgColor=\"#$tdBg1\" Align=right><b><Font
Color=black>$currency $gtot</Font></b><Tr>\n";

should I make a sub total to subtract that from the total because right now
the grand total equals the final mulitplied number? and I need the
multiplied number to be subtracted from the grand total.




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

Date: Wed, 11 Nov 1998 14:36:51 -0600
From: forrest reynolds <forrest7@realtime.net>
Subject: Perl,ActiveS,run?
Message-Id: <3649F562.1F7EB75E@realtime.net>

Hello,
     I recently downloaded build 316 of ActiveState's Perl for Win32. I
run Win 95 and I'm having trouble running a simple (print "hello
world\n";) progam that I saved under the title   hello.pl in the
Perl\bin. My path is c:\Perl\bin and I try to run it from the Perl.exe
(looks like a DOS window) that is in Perl\bin. I've checked Faqs and
such, but when I type "perl hello.pl" or c:\Perl\bin  hello.pl    and
other variations, the cursor just skips to the next line. How can I get
this to run? I want to start practicing more complex programs....
thanks, Forrest

p.s. if anyone knows how to get Netscape Navigator 4.06 to stop MIME
attachment, I'd love to know how! :-)



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

Date: Wed, 11 Nov 1998 11:31:59 -0800
From: Raphe Berry III <raphe.berry@sun.com>
Subject: question about array naming
Message-Id: <3649E62F.4FC84339@sun.com>

I am updating some perl code that I didn't write and I have ran into a
variable which looks something like this:  @$variable . What does @$
denote?
Is it both a scalar and an array?


thanks

Raphe



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

Date: Wed, 11 Nov 1998 20:36:52 +0000
From: Jason Holland <jason.holland@dial.pipex.com>
To: Raphe Berry III <raphe.berry@sun.com>
Subject: Re: question about array naming
Message-Id: <3649F564.5D8DF35@dial.pipex.com>

Raphe Berry III wrote:
> 
> I am updating some perl code that I didn't write and I have ran into a
> variable which looks something like this:  @$variable . What does @$
> denote?
> Is it both a scalar and an array?
> 
> thanks
> 
> Raphe

Hello,

What you have there is an array reference. Check 'man perlref' for more
details.

I assume that this is happening inside a subroutine? Essentially, you
may want to use this if you need to pass an array and something else,
such as a hash, into a subroutine as arguments.

Create and use an array ref like this:

	my @array = ( "Goodbye", "cruel" ); # Create array
	my $arrayRef = \@array;             # Create reference to array
	my $string = "world\n";
	function( $arrayRef, $string );     # Pass stuff into sub

	sub function() {
		my $arrayRef = shift;
		my $string   = shift;
		foreach ( @$arrayRef ) {    # Iterate over dereferenced array
			print $_;
		}
		print $string;
		return(1);
	}


Check it for errors!

Hope this helps. Bye the way, look for the "Perl Desktop Reference", it
crams all of the different variable thingies into a couple of pages, and
only costs a fiver. I use it more than any other Perl book!

Bye!


-- 
sub jasonHolland {
    my %hash = ( website =>
'http://dspace.dial.pipex.com/jason.holland/',
                 email   => 'jason.holland@dial.pipex.com' );
}


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

Date: Wed, 11 Nov 1998 20:33:07 GMT
From: Dave.Rathnow@cadvision.com (Dave Rathnow)
Subject: Regular expression questions
Message-Id: <3649f426.94909612@news.cadvision.com>


I have a string of characters from which I need to extract the first
23 characters.  Everything form the 24 character to the end of
the line must go.

Could someone tell me what the regular expression for such an
operation would be?

Thanks,
Dave.


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

Date: Wed, 11 Nov 1998 14:12:26 -0500
From: Robert Mohid <mohid@nortel.ca>
Subject: Submitting binary data with post?
Message-Id: <3649E19A.C4386369@nortel.ca>

Is there a way to submit binary data (an image file for ex) to a cgi
interface?

I don't think it's possible using a forms based html page but I may be
wrong,
I expect to be forced to write something that will setup the HTTP
connection
and format the stream accordingly but any solution would do.

Any suggestions?

--
'Later

Robert      robert_mohid at cyberus dot ca
*********************************





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

Date: Wed, 11 Nov 1998 20:38:49 +0000
From: Jason Holland <jason.holland@dial.pipex.com>
To: Robert Mohid <mohid@nortel.ca>
Subject: Re: Submitting binary data with post?
Message-Id: <3649F5D9.89E6F460@dial.pipex.com>

Robert Mohid wrote:
> 
> Is there a way to submit binary data (an image file for ex) to a cgi
> interface?
> 
> I don't think it's possible using a forms based html page but I may be
> wrong,
> I expect to be forced to write something that will setup the HTTP
> connection
> and format the stream accordingly but any solution would do.
> 
> Any suggestions?
> 
> --
> 'Later
> 
> Robert      robert_mohid at cyberus dot ca
> *********************************

Hello,

Yeah, there is an 'Attach File' type option available with newer version
of Netscape, and Explorer I believe.

I only tried using it once, with mixed results if I remember correctly.
Look it up in the newer O'Reilly HTML book.

Bye!


-- 
sub jasonHolland {
    my %hash = ( website =>
'http://dspace.dial.pipex.com/jason.holland/',
                 email   => 'jason.holland@dial.pipex.com' );
}


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

Date: Wed, 11 Nov 1998 21:43:26 +0100
From: "Casema" <ours@casema.net>
Subject: value not entered
Message-Id: <72csvt$ohq$1@sun4000.casema.net>

Hi group....yup, me again.
when a user fills out a form, I check the values and return the form with
labels RED if they have to re-enter some data.
All works fine and user get's back the form with the values they entered,
fine too!

but.... it does not seem to work for a textarea....... how's that????

So:

  print "<INPUT NAME=\"teln\" SIZE=\"20\" VALUE=$dat[10]>\n";

works!!!!!
but:

  print "<TEXTAREA NAME=\"text\" ROWS=\"12\" COLS=\"48\"
VALUE=$dat[13]\n></TEXTAREA>\n";

(neither if I put $dat[13] in between \"   \"

does not????

Anyone???
thanks,

michel




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

Date: 11 Nov 1998 21:43:43 +0100
From: Joakim Hove <hove@ido.phys.ntnu.no>
Subject: Value of <HANDLE> construct can be "0"...
Message-Id: <k0n3e7qm03k.fsf@ido.phys.ntnu.no>

Hello,

im trying to run my perl scripts with the -w option. However every
time I try to open a file a get the warning : 

    Value of <HANDLE> construct can be "0"; test with defined() 
	at ./lpr_farge.pl line 65535.

My script is way less than 65535 lines long, so this linenumber does
not correspond to a line in my code.

I open the file with


if (open(FILE , "filename) {
    while ($line = <FILE>) {
	do-something
    } 
    close(FILE);
}


If anyone knows why this warning appears, and how i can apply the
defined() test mentioned in the warning I would be very grateful.

Joakim Hove


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

Date: Wed, 11 Nov 1998 19:40:39 GMT
From: gustafl@algonet.se (Gustaf Liljegren)
Subject: XQL
Message-Id: <3649e836.42041247@news.algonet.se>

During the past two weeks I have experienced Perl for the first time.
I got into Perl from XML, and this may still be an unusual way to
enter it. However, Perl seems to suit XML perfectly. I became to think
that Perl may help the XML dream to become reality, and XML may help
Perl to become The Programming Language for the web. Yes it already
is, but perhaps even more than today... :-)

But, today I read a little about XQL. "The XML Query Language (XQL) is
a notation for adressing and filtering the elements and text of XML
documents" [http://www.w3.org/TandS/QL/QL98/pp/xql.html]. Wow, that
sounds like the Perl script I wrote yesterday...

In the authors list it looks like XQL is a Micro$oft idea developed
for W3C. Obviously M$ can't accept Perl to remain as The Programming
Language of the web in the near future. The specification (see URL
above) does not mention Perl. This means that it's too close to Perl
or far away from it. I belive the former.

Am I right that XQL is an alternative for Perl? 

--
Gustaf Liljegren



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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 4199
**************************************

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