[13962] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1372 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Nov 13 21:10:25 1999

Date: Sat, 13 Nov 1999 18:10:14 -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: <942545414-v9-i1372@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Sat, 13 Nov 1999     Volume: 9 Number: 1372

Today's topics:
    Re: pattern matching packages (Kragen Sitaker)
    Re: pattern matching packages (Martien Verbruggen)
    Re: pattern matching packages (Kragen Sitaker)
    Re: Problems with indexer.pl (Perlfect Search) Any sugg (Kragen Sitaker)
    Re: regular expression riddle <reembar@netvision.net.il>
    Re: regular expression riddle (Kragen Sitaker)
        Reposted (slightly less confusing?)- searching flatfile <ben@smooth.co.uk>
    Re: Reposted (slightly less confusing?)- searching flat (Kragen Sitaker)
    Re: Reposted (slightly less confusing?)- searching flat <ben@smooth.co.uk>
    Re: Reposted (slightly less confusing?)- searching flat (Kragen Sitaker)
    Re: return height and width of jpeg, gif accessed via u (Martien Verbruggen)
    Re: return height and width of jpeg, gif accessed via u (Kragen Sitaker)
    Re: return height and width of jpeg, gif accessed via u (Martien Verbruggen)
    Re: searching flatfile with a hash (Tad McClellan)
    Re: searching flatfile with a hash <ben@smooth.co.uk>
    Re: searching flatfile with a hash <ben@smooth.co.uk>
    Re: Show me a better way! (Craig Berry)
        unique search and replace problem rancorr@hotmail.com
    Re: Weekday in perl (Viscano)
    Re: What module for adding messages to mail folders? (Martien Verbruggen)
    Re: Which browser? (Kragen Sitaker)
    Re: Which browser? <slanning@bu.edu>
    Re: Writing data to file on another server. (Kragen Sitaker)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Sat, 13 Nov 1999 23:36:09 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: pattern matching packages
Message-Id: <JBmX3.8136$YI2.321250@typ11.nn.bcandid.com>

In article <382C9ABF.2B65C6A4@mail.cor.epa.gov>,
David Cassell  <cassell@mail.cor.epa.gov> wrote:
>Perl has all the regex features you'll need already built in.
>Read the perlre and perlop pages to learn more.

I don't think so.  Here are some features Perl's REs don't have, which
might be thought desirable.  I would be pleasantly surprised if any
significant number of these actually get implemented.

- doing something with regexes other than just searching text with
  them.  
	- For example, for a tokenizer, I would like Perl to verify for
	  me that any sequence of characters can be matched by the
	  tokenizer RE, ideally in only one way.  This is computable
	  for real REs; I don't know if it's computable for Perl REs
	  including backreferences, backward positive and negative
	  assertions, etc., and I know it isn't computable for Perl REs
	  including Perl code blocks.  But I don't use those in
	  tokenizer REs.
	- Someone asked recently on this newsgroup how to compute all
	  the possible ways an RE like ([a-z]*)(.*) could match a
	  particular string.
	- It would be nice to be able to compute whether or not a
	  particular RE was capable of requiring exponential time -- or
	  at least whether it could be guaranteed to be evaluated in
	  linear time.
	- it would also be nice to be able to test whether two REs are
	  equivalent, in the sense of being able to match the same set
	  of strings (or stronger, being guaranteed to find the same
	  string when matched.)  This is handy if you want to verify
	  that hand-optimizing a certain RE to make it faster didn't
	  break anything.
- guaranteed polynomial-time matching, at least for 'simple' REs that
  don't use advanced features.  Friedl's book says Henry Spencer is
  working on a DFA-based regex engine with gewgaws like capturing
  parens and backreferences that is guaranteed to be no worse than
  quadratic time (instead of exponential-time like Perl's NFA engine).
- related to that: the ability to suspend and resume an RE match.  For
  example, if I'm matching an RE on a file, it would be nice to match a
  line at a time.  Sometimes this requires arbitrarily large storage
  (for capturing parens and backrefs) and sometimes it doesn't.  (It
  would be nice to be able to ask when it does and when it doesn't.)
- did Perl ever fix the problem mentioned in Friedl's book with /i
  making a copy of the whole haystack, murdering efficiency when doing
  multiple case-insensitive matches on large haystacks?
- [character classes] that can include Unicode characters.
- better handling of $`, $', and $&.  Right now, apparently, aliasing
  *& to *MATCH in English.pm turns off all kinds of optimizations.
  It would be nice if they were only turned off if $MATCH got used.
- Sometimes I would like 'set-subtraction' for RE's.  For example,
  parsing XML CDATA sections, I'd like to match .* minus \]\]>, which
  is how the syntax is specified in the XML spec.  I can, of course,
  write the RE for that myself -- it looks something like
  (?#untested)(?x: [^]] | \] (?: [^]] | \]+ [^]>] ) )* -- but it's
  pretty hideous.  Nongreedy matches remove a lot of the need for this,
  but they can backtrack and chomp up terminators unexpectedly if they
  have to to get something later in your pattern to match.
  Oh, wait -- Perl already has this.  We have (?:(?!]]>).)*.

Perl already has some amazing features other languages don't -- minimal
matching, set-intersection of REs (?=), set subtraction of REs,
lookbehind and lookahead assertions, embedded Perl, tight control over
backtracking with (?>) and friends, conditional expressions, and lots
of other stuff I never use.  So please don't think I'm complaining -- I
only want to spark thought.
-- 
<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>


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

Date: 14 Nov 1999 00:02:08 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: pattern matching packages
Message-Id: <slrn82rv1c.igg.mgjv@wobbie.heliotrope.home>

On Sat, 13 Nov 1999 23:36:09 GMT,
	Kragen Sitaker <kragen@dnaco.net> wrote:

> - doing something with regexes other than just searching text with
>   them.  
[snip]
> 	- Someone asked recently on this newsgroup how to compute all
> 	  the possible ways an RE like ([a-z]*)(.*) could match a
> 	  particular string.

There is only one way in which this regexp can match a particular
string, or am I misunderstanding you? The ([a-z]*) will match as many
characters as it can that satisfy the character class, starting from the
leftmost character that matches. The rest goes in the (.*). Or are you
suggesting to change the greediness or left-most match character of
regexps in Perl?

Or are you really asking for a new sort of syntax that will, instead of
applying the standard rules, switch to matching everything possible? So
that matching against

-- - - - abc -- -

would return lists of ('a', 'bc -- -'), ('ab', 'c -- -') and 
('abc', ' -- -')? In effect adapting greediness or something like that? 
Oh, and the list (undef, 'abc -- -') would probably need to be the
first.

I think I can feel a lot of possibilities for runaway stuff coming up
here :)

> of other stuff I never use.  So please don't think I'm complaining -- I
> only want to spark thought.

Some of the things you mention could be useful.  I know that I won't
ever even get near some other ones you talked about though :)

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In a world without fences, who needs
Commercial Dynamics Pty. Ltd.   | Gates?
NSW, Australia                  | 


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

Date: Sun, 14 Nov 1999 00:14:35 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: pattern matching packages
Message-Id: <L9nX3.8195$YI2.324551@typ11.nn.bcandid.com>

In article <slrn82rv1c.igg.mgjv@wobbie.heliotrope.home>,
Martien Verbruggen <mgjv@comdyn.com.au> wrote:
>On Sat, 13 Nov 1999 23:36:09 GMT,
>	Kragen Sitaker <kragen@dnaco.net> wrote:
>> - doing something with regexes other than just searching text with
>>   them.  
>[snip]
>> 	- Someone asked recently on this newsgroup how to compute all
>> 	  the possible ways an RE like ([a-z]*)(.*) could match a
>> 	  particular string.
>
>There is only one way in which this regexp can match a particular
>string, or am I misunderstanding you? The ([a-z]*) will match as many
>characters as it can that satisfy the character class, starting from the
>leftmost character that matches. The rest goes in the (.*). 

Well, it'll match that way if it succeeds.  But if stuff after it in
the RE fails, it'll backtrack and match different ways.  Etc.

>Or are you suggesting to change the greediness or left-most match character of
>regexps in Perl?
>
>Or are you really asking for a new sort of syntax that will, instead of
>applying the standard rules, switch to matching everything possible? So
>that matching against
>
>-- - - - abc -- -
>
>would return lists of ('a', 'bc -- -'), ('ab', 'c -- -') and 
>('abc', ' -- -')? In effect adapting greediness or something like that? 
>Oh, and the list (undef, 'abc -- -') would probably need to be the
>first.

Right, exactly.  Except the decision about whether to apply the normal
rules and just match, or whether to generate these lists, would not be
written as part of the regex, but would be determined by which
operation you used to apply the regex.

>I think I can feel a lot of possibilities for runaway stuff coming up
>here :)

Yes.  (.*)* can match in an awful lot of ways.
-- 
<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>


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

Date: Sun, 14 Nov 1999 00:00:46 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Problems with indexer.pl (Perlfect Search) Any suggestions?
Message-Id: <OYmX3.8165$YI2.321566@typ11.nn.bcandid.com>

In article <8E7C6BF04kashmirallaccessentc@208.155.7.134>,
Kashmir <kashmir@all-access-ent.com> wrote:
>site) put up and I went to CGI Resources (www.cgi-resources.com) and looked 
>through their Perl scripts. I tried a few out and thought I found one that 
>looked fairly easy to setup and run. It's called Perlfect Search. 

 . . .

>sdbm store returned -1, errno 22, key "76" at ./indexer.pl line 140.
>
>   So I'm wondering if anyone could help me out. I understand it could be a 
>Perl script error in line 140... so not knowing a whole lot about Perl I first 
>counted down to line 140 
>
>   print "|----|----|----|----|----|----|----|----|----|----|\n";
>   (is line 140 counting all lines)

I don't know about you, but I have a hard time counting to 140 without
making any mistakes.  I'm assuming you counted wrong, because this line
isn't storing anything in an sdbm file.

>   $buffer =~ s/\b$_\b//gis;
>   (is line 140 counting no blank lines)

And neither is this one.

Consider printing out the output of cat -n indexer.pl, or saving it to
a file (cat -n indexer.pl > name_of_the_file) and looking in that
file.  Computers are better at counting than people.

Consider, also, that there are places to get good CGI scripts (Randal's
WebTechniques columns, for example) and places to get bad ones, like
www.cgi-resources.com.

Hey, UNCRAP people: www.mattright.com still only has a placeholder
page.  What's up?
-- 
<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>


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

Date: Sun, 14 Nov 1999 01:24:03 +0200
From: Re'em Bar <reembar@netvision.net.il>
To: Kragen Sitaker <kragen@dnaco.net>
Subject: Re: regular expression riddle
Message-Id: <382DF313.16A2078@netvision.net.il>

thanks for your learned reply!
Since I use Active Perl and have little experience on Unix, the Unix
shape links to different FAQs are a bit of a puzzle to me, so your
elaborate reply was very handy.
-- 
Re'em
http://snark.co.il


Kragen Sitaker wrote:
> 
> In article <382DAE36.E0174516@netvision.net.il>,
> Re'em Bar  <reembar@netvision.net.il> wrote:
> >I want to change any word so it begins with CAPS
> >the little rabbit => The Little Rabbit
> >hope it's not in the FAQ too...
> 
> perldoc -q capital
> =head1 Found in /usr/local/lib/perl5/5.00503/pod/perlfaq4.pod
> 
> =head2 How do I capitalize all the words on one line?
> 
> To make the first letter of each word upper case:
> 
>         $line =~ s/\b(\w)/\U$1/g;
> 
> This has the strange effect of turning "C<don't do it>" into "C<Don'T
> Do It>".  Sometimes you might want this, instead (Suggested by Brian
> Foy):
> 
>     $string =~ s/ (
>                  (^\w)    #at the beginning of the line
>                    |      # or
>                  (\s\w)   #preceded by whitespace
>                    )
>                 /\U$1/xg;
>     $string =~ /([\w']+)/\u\L$1/g;
> 
> To make the whole line upper case:
> 
>         $line = uc($line);
> 
> To force each word to be lower case, with the first letter upper case:
> 
>         $line =~ s/(\w+)/\u\L$1/g;
> 
> You can (and probably should) enable locale awareness of those
> characters by placing a C<use locale> pragma in your program.
> See L<perllocale> for endless details on locales.
> 
> This is sometimes referred to as putting something into "title
> case", but that's not quite accurate.  Consdier the proper
> capitalization of the movie I<Dr. Strangelove or: How I Learned to
> Stop Worrying and Love the Bomb>, for example.
> 
> >also, excuse my ignorance, but is there a way to pass more then one
> >array to a subroutine, not into the @_?
> 
> By reference.
> --
> <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>


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

Date: Sun, 14 Nov 1999 00:07:32 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: regular expression riddle
Message-Id: <83nX3.8179$YI2.326049@typ11.nn.bcandid.com>

In article <382DF313.16A2078@netvision.net.il>,
Re'em Bar  <reembar@netvision.net.il> wrote:
>thanks for your learned reply!
>Since I use Active Perl and have little experience on Unix, the Unix
>shape links to different FAQs are a bit of a puzzle to me, so your
>elaborate reply was very handy.

perldoc is included with ActivePerl, and the full Perl documentation --
which includes the FAQ entry below -- is on your Start menu.


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


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

Date: Sat, 13 Nov 1999 23:29:50 -0000
From: Ben Osman <ben@smooth.co.uk>
Subject: Reposted (slightly less confusing?)- searching flatfile with a hash
Message-Id: <MPG.129804968df518e4989682@news.btinternet.com>

hello again

thanks for your help so far

sorry I have not been explaining myself all that well it has been a 
hectic day

I will attempt to explain myself better (but probably fail :-)
if you are reading this thanks for your patience!

I was trying to find the best way to look up a collection of items 
gathered from a shopping cart.
here is the code for the cart - further below is my initial attempt 
to check the items within a datafile.
--------------------------------------------
sub opencartfile
{

# array number is used to make sure each item has a unique no in array
# I have passed three arguments into the subroutine - a ref to an array 
# which is now pointed to by $arrayref and will later be allocated
# @open_cart_row when returned
# 
# this part was working so any mistakes other than lazy/bad/uninformed
# programming is due to carelessness on cut and paste.

my $array_number = -1;
my $arrayref = shift;
my $reason = shift;
my $file_path = shift;
my (@open_cart_row); 
open (CART, "$file_path");

while (my $cartline = <CART>)
   {
   chomp $cart_row;
   my @cartrow = split (/\|/, $cartline);	
   my $array_item = ++$array_number;
   $open_cart_row[$array_item]{id} = @cartrow[0];
   $open_cart_row[$array_item]{category} = @cartrow[1];
   $open_cart_row[$array_item]{quantity} = @cartrow[2];
   $open_cart_row[$array_item]{options} = @cartrow[3];
   $open_cart_row[$array_item]{itemid} = @cartrow[4];
   } 
close (<CART>);

continued below
----------------------------------------------------------
at the moment I have built up an array of items from the cart.
@open_cart_row

each item in the cart is a hash within the array, whether this is the 
best idea or not I am not sure but I have just learnt how to do it!
this hash contains the keys id and quantity.

my reason for doing this is so that I can get at different attributes of 
the product, for display (I will be passing to a template)

I now need to, for each item in the cart(each $hash{id} within the array)  
check the product id within the datafile, and insert the extra 
information as required into extra key/value pairs.

I have considered using something like : 
--------------------------------------------
open (DATAFILE, "./data_files/data.file");
 
foreach my $item(@open_cart_row)#this gets at each hash within the array
{
my $product_id = @$item{id}; # this accesses the id key foreach hash/item

while ((my $dataline = <DATAFILE>)&&
      ($product_id ne $db_product_id)) # this is so it stops when id                                                                                                                                                                   
# matches the one in datafile
  { 
  my @db_row = split (/\|/, $dataline);  # assigning scalars to place
  my $db_product_id = $db_row[0];        # within the hash
  my $db_category = $db_row[1];
  my $db_price = $db_row[2];
  my $db_name = $db_row[3];

  #then I would use a if block and flag to find out if the item matched
  # and if true make the addition of whatever info I wanted into the hash
  } # end of while
} # end of foreach
close (<DATAFILE>);
@$arrayname = @open_cart_row; # the array of hases is then allocated 
                              # to the reference I passed in initially
} #end of sub opencartfile (started in top section of code)
------------------------------------------------------------------------
the problem I have with this is I would like to search for all products 
in a single pass as I believe it would be more efficient.

I would think it would be best to use a while loop with some logic that 
searches for all items in the cart;

would I be best to put the id's into a separate hash?

any insights would be gratefully received

and once again thanks for your patience;

regards

Ben


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

Date: Sat, 13 Nov 1999 23:51:49 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Reposted (slightly less confusing?)- searching flatfile with a hash
Message-Id: <pQmX3.8152$YI2.323852@typ11.nn.bcandid.com>

In article <MPG.129804968df518e4989682@news.btinternet.com>,
Ben Osman  <ben@smooth.co.uk> wrote:
>I was trying to find the best way to look up a collection of items 
>gathered from a shopping cart.
>here is the code for the cart - further below is my initial attempt 
>to check the items within a datafile.
>--------------------------------------------
>sub opencartfile
>{
>
># array number is used to make sure each item has a unique no in array
># I have passed three arguments into the subroutine - a ref to an array 
># which is now pointed to by $arrayref and will later be allocated
># @open_cart_row when returned
># 
># this part was working so any mistakes other than lazy/bad/uninformed
># programming is due to carelessness on cut and paste.
>
>my $array_number = -1;
>my $arrayref = shift;
>my $reason = shift;
>my $file_path = shift;
>my (@open_cart_row); 
>open (CART, "$file_path");
>
>while (my $cartline = <CART>)
>   {
>   chomp $cart_row;
>   my @cartrow = split (/\|/, $cartline);	
>   my $array_item = ++$array_number;
>   $open_cart_row[$array_item]{id} = @cartrow[0];
>   $open_cart_row[$array_item]{category} = @cartrow[1];
>   $open_cart_row[$array_item]{quantity} = @cartrow[2];
>   $open_cart_row[$array_item]{options} = @cartrow[3];
>   $open_cart_row[$array_item]{itemid} = @cartrow[4];

It looks like you want 
	chomp $cartline;
	my %hash;
	@hash{qw(id category quantity options itemid)} = split /\|/, $cartline;
	push @open_cart_row, \%hash;

I assume chomp $cart_row is a mistake -- probably one that would be
caught by either of -w or use strict.

By the way, why are you using @open_cart_row instead of @$arrayref?

>----------------------------------------------------------
>at the moment I have built up an array of items from the cart.
>@open_cart_row
>
>each item in the cart is a hash within the array, whether this is the 
>best idea or not I am not sure but I have just learnt how to do it!
>this hash contains the keys id and quantity.

Sounds good to me.

>I now need to, for each item in the cart(each $hash{id} within the array)  
>check the product id within the datafile, and insert the extra 
>information as required into extra key/value pairs.
>
>I have considered using something like : 
>--------------------------------------------
>open (DATAFILE, "./data_files/data.file");
> 
>foreach my $item(@open_cart_row)#this gets at each hash within the array
>{
>my $product_id = @$item{id}; # this accesses the id key foreach hash/item
>
>while ((my $dataline = <DATAFILE>)&&
>      ($product_id ne $db_product_id)) # this is so it stops when id    
>
># matches the one in datafile
>  { 
>  my @db_row = split (/\|/, $dataline);  # assigning scalars to place
>  my $db_product_id = $db_row[0];        # within the hash
>  my $db_category = $db_row[1];
>  my $db_price = $db_row[2];
>  my $db_name = $db_row[3];
>
>  #then I would use a if block and flag to find out if the item matched
>  # and if true make the addition of whatever info I wanted into the hash
>  } # end of while
>} # end of foreach
>close (<DATAFILE>);
>@$arrayname = @open_cart_row; # the array of hases is then allocated 
>                              # to the reference I passed in initially
>} #end of sub opencartfile (started in top section of code)
>------------------------------------------------------------------------
>the problem I have with this is I would like to search for all products 
>in a single pass as I believe it would be more efficient.
>
>I would think it would be best to use a while loop with some logic that 
>searches for all items in the cart;
>
>would I be best to put the id's into a separate hash?

Yes.  If I were doing it, I'd probably put DATAFILE's contents into a
hash by id and then iterate over @open_cart_row, extracting the
appropriate data from the hash.  But -- assuming @open_cart_row is
guaranteed not to have two line items with the same id -- you could do
it the other way, too, putting @open_cart_row's contents into a hash by
id and then iterating over DATAFILE's contents.

Hope this helps!
-- 
<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>


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

Date: Sun, 14 Nov 1999 00:26:39 -0000
From: Ben Osman <ben@smooth.co.uk>
Subject: Re: Reposted (slightly less confusing?)- searching flatfile with a hash
Message-Id: <MPG.129811fb8563420c989685@news.btinternet.com>

hello once again

> 
> It looks like you want 
> 	chomp $cartline;
> 	my %hash;
> 	@hash{qw(id category quantity options itemid)} = split /\|/, $cartline;
> 	push @open_cart_row, \%hash;

I will probably bring the keys in from another array in a setup file, so 
I just put them in b4 I figured out where. 

thanks for the help though that makes it look a lot simpler, 

if I wanted to bring the keys from an array would i replace the keys with 
the array and remove the qw?

eg. @hash{(@cart_hash_keys)} = split /\|/, $cartline;


> 
> I assume chomp $cart_row is a mistake -- probably one that would be
> caught by either of -w or use strict.

yes the chomp $cart_row was left in from a previous attempt

> 
> By the way, why are you using @open_cart_row instead of @$arrayref?

I was using the @open_cart_row previously, when I was not intending to 
reuse the subroutine and have only just started to use refs,

thanks again


ben


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

Date: Sun, 14 Nov 1999 01:14:37 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Reposted (slightly less confusing?)- searching flatfile with a hash
Message-Id: <12oX3.8327$YI2.335679@typ11.nn.bcandid.com>

In article <MPG.129811fb8563420c989685@news.btinternet.com>,
Ben Osman  <ben@smooth.co.uk> wrote:
>> 	@hash{qw(id category quantity options itemid)} = split /\|/, $cartline;
>
>I will probably bring the keys in from another array in a setup file, so 
>I just put them in b4 I figured out where. 
>
>thanks for the help though that makes it look a lot simpler, 
>
>if I wanted to bring the keys from an array would i replace the keys with 
>the array and remove the qw?
>
>eg. @hash{(@cart_hash_keys)} = split /\|/, $cartline;

Sure.  You don't even need the ().



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


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

Date: 14 Nov 1999 00:38:01 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: return height and width of jpeg, gif accessed via url
Message-Id: <slrn82s14p.igg.mgjv@wobbie.heliotrope.home>

On 13 Nov 1999 18:05:47 GMT,
	BLUESRIFT <bluesrift@aol.com> wrote:
[reformat to fit on a 80 character screen]

> Elsewhere Faisal Nasim helpfully shared the following routine that
> returns the height and width of a gif file along with "type" which
> could be used for capturing errors resulting from a misnamed file.
> This works fine for gif images that can be addressed via a path to a
> file on the same server.  I am seeking routine(s) that will return
> this type of information for either a gif or a jpeg

Get rid of the handrolled code, and get yourself the Image::Size module.

> AND will work instead for files accessed via a url.  I am aware of the

That is impossible. Tobe able to read the contents of an image, you will
first have to download it to local disk. Unless you are using a protocol
that allows you to ask for image sizes on the other end.

get libwww, aka LWP from CPAN as well, while you're there to get
Image::Size

> Image::Size module and of other more comprehensive utilities to
> accomplish this but please trust me that I need a solution that
> requires only standard distribution modules.  I don't know if LWP is
> standard, but it is available and could be useful?  

God, not more of this nonsense[*]. Image::Size is the way to go in this
case. If you don't like it, or feel it's too much trouble packing it up
with your code, then copy and paste the code out of it into your
program. If you don't want to use standard modules, then you are doomed
to have to recode the wheel every single time, and you are responsible
for fixing the bugs and keeping it up to date.

What exactly is the difference between using a module and adding that
code to your own scripts?  How hard is it to create a distribution that
includes the modules?

And good luck writing that functionality of LWP for yourself.

# perldoc -f socket

Martien

[*] I still have to hear one single valid reason not to use modules from
CPAN (apart from them not satisfying your need). Paranoia from managers
doesn't count, and can be circumvented by packing the module in with
your own code.

-- 
Martien Verbruggen              | My friend has a baby. I'm writing
Interactive Media Division      | down all the noises the baby makes so
Commercial Dynamics Pty. Ltd.   | later I can ask him what he meant -
NSW, Australia                  | Steven Wright


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

Date: Sun, 14 Nov 1999 01:21:13 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: return height and width of jpeg, gif accessed via url
Message-Id: <d8oX3.8337$YI2.337323@typ11.nn.bcandid.com>

In article <slrn82s14p.igg.mgjv@wobbie.heliotrope.home>,
Martien Verbruggen <mgjv@comdyn.com.au> wrote:
>What exactly is the difference between using a module and adding that
>code to your own scripts?

1. package main; and some calls to import methods;
2. upgrading to a new version of the module is harder when you have
included the module in your script.

Generally it's better to use the FAQ's answer and create a module
directory, IMHO.


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


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

Date: 14 Nov 1999 01:56:33 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: return height and width of jpeg, gif accessed via url
Message-Id: <slrn82s5o2.jb7.mgjv@wobbie.heliotrope.home>

On Sun, 14 Nov 1999 01:21:13 GMT,
	Kragen Sitaker <kragen@dnaco.net> wrote:
> In article <slrn82s14p.igg.mgjv@wobbie.heliotrope.home>,
> Martien Verbruggen <mgjv@comdyn.com.au> wrote:
> >What exactly is the difference between using a module and adding that
> >code to your own scripts?
> 
> 1. package main; and some calls to import methods;

Not necessarily main:: :)

> 2. upgrading to a new version of the module is harder when you have
> included the module in your script.

Indeed. And that just strengthens my point.

> Generally it's better to use the FAQ's answer and create a module
> directory, IMHO.

iAnd I agree here. But the OP said there were valid reasons not to use
modules that don't come with the Perl distribution. While I doubt that
very much, as expressed in my previous post, a way the deluded can get
around using modules at all is by putting the module code in their
scripts. Of course, they are then _still_ usign the module. They just
got rid of some of the benefits as you pointed out. And that was what I
really meant with my question :).

I don't know why people don't seem to get that using a module is no
different from writing your own code (apart from the points you made,
and one or two others), and keep insisting on this 'no other modules
than the standard ones' crap.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | If it isn't broken, it doesn't have
Commercial Dynamics Pty. Ltd.   | enough features yet.
NSW, Australia                  | 


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

Date: Sat, 13 Nov 1999 13:19:13 -0500
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: searching flatfile with a hash
Message-Id: <slrn82rat1.31n.tadmc@magna.metronet.com>

On Sat, 13 Nov 1999 17:40:12 -0000, Ben Osman <ben@smooth.co.uk> wrote:

>I need to search a flatfile database for several queries and would like 
>help on the way this is most efficient. 

>I am not sure on how to search for multiple items without doing multiple 
>passes. 


   Perl FAQ, part 6:

      "How do I efficiently match many regular expressions at once?"


> I can get it working using foreach with a while nested but this 
>is rather inefficient as it has to go through the data file for each 
>product.


   The FAQ above says that that approach is "super-inefficient",
   as you have correctly surmised.


>I am still learning perl and have fairly good knowledge of while and 
>foreach loops, but at the moment I am struggling to get my head round 
>this.
>
>I would be grateful if someone could point me in the right direction on 
>how to approach this.


   my $keyRE = join '|' reverse sort keys %somehash;  # key1|key2|key3|...

   while (<>) {
      print "found $1\n" if /($keyRE)/;
   }


-- 
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Sat, 13 Nov 1999 23:39:32 -0000
From: Ben Osman <ben@smooth.co.uk>
Subject: Re: searching flatfile with a hash
Message-Id: <MPG.1298070edfc9a877989683@news.btinternet.com>

hi again

thanks for your help so far kragen

I have reposted a clearer example with a bit of the code in question. 

the stock was merely going to be  backorder / short supply / well stocked
as there is no live link up between the companies existing databases.

I was thinking about a clearance item system where there would be limited 
items to sell on the internet - in that case I would use flock and a 
separate file to stop double selling from occurring

I have read the database article you mentioned - very interesting, 
The problem is we are designing a script to work with a client based 
controller as part of a package and the script needs to be cross isp, 
therefore although a RBDMS would be a much better option if we were doing
it for ourselves, I will have to stick with flatfiles for the moment :(.

thanks

Ben


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

Date: Sat, 13 Nov 1999 23:49:49 -0000
From: Ben Osman <ben@smooth.co.uk>
Subject: Re: searching flatfile with a hash
Message-Id: <MPG.129809759cee1ab5989684@news.btinternet.com>

thanks tad 

I will check this out, I have just posted a new message with some of my 
code which I did not really need to do as I now know where to look.

I must of missed that in the FAQ.

thanks again

Ben

 



In article <slrn82rat1.31n.tadmc@magna.metronet.com>, tadmc@metronet.com 
says...
> On Sat, 13 Nov 1999 17:40:12 -0000, Ben Osman <ben@smooth.co.uk> wrote:
> 
> >I need to search a flatfile database for several queries and would like 
> >help on the way this is most efficient. 
> 
> >I am not sure on how to search for multiple items without doing multiple 
> >passes. 
> 
> 
>    Perl FAQ, part 6:
> 
>       "How do I efficiently match many regular expressions at once?"
> 
> 
> > I can get it working using foreach with a while nested but this 
> >is rather inefficient as it has to go through the data file for each 
> >product.
> 
> 
>    The FAQ above says that that approach is "super-inefficient",
>    as you have correctly surmised.
> 
> 
> >I am still learning perl and have fairly good knowledge of while and 
> >foreach loops, but at the moment I am struggling to get my head round 
> >this.
> >
> >I would be grateful if someone could point me in the right direction on 
> >how to approach this.
> 
> 
>    my $keyRE = join '|' reverse sort keys %somehash;  # key1|key2|key3|...
> 
>    while (<>) {
>       print "found $1\n" if /($keyRE)/;
>    }
> 
> 
> 


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

Date: Sun, 14 Nov 1999 00:43:21 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Show me a better way!
Message-Id: <s2s1d92fhsq55@corp.supernews.com>

Jody Fedor (JFedor@datacom-css.com) wrote:
: I know this isn't bad when only doing a few comparisons
: but if there were 10 or 20 the code would be functional
: but a nitemare.  How could it be written simpler?
: 
: if ($cookies{'state'} eq "OH") {$tax = ($tcost * .055) + .005}
: elsif ($in{'fstate'} eq "OH") {$tax = ($tcost * .055) + .005}
: else {$tax = 0.00};

  %taxes = ( OH => .055,
             CA => .075,
             IN => .060
             # ...and so forth...
           );

  $tax = 0.00;

  if (exists $cookies{state}) {
    if (exists $taxes{$cookies{state}}) {
      $tax = $tcost * $taxes{$cookies{state}} + 0.005;
    }
  elsif (exists $in{fstate}) {
    if (exists $taxes{$in{fstate}}) {
      $tax = $tcost * $taxes{$in{fstate}} + 0.005;
    }
  }

-- 
   |   Craig Berry - cberry@cinenet.net
 --*--  http://www.cinenet.net/users/cberry/home.html
   |   "They do not preach that their God will rouse them
      a little before the nuts work loose." - Kipling


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

Date: Sun, 14 Nov 1999 01:28:04 GMT
From: rancorr@hotmail.com
Subject: unique search and replace problem
Message-Id: <80l372$cig$1@nnrp1.deja.com>

I have a long text files which contain the following types of entries:

<option value="232">Bain & Company

<option value="129">Baker & Botts

<option value="67232">Baker & McKenzie

I want to create a Perl script that will replace the numbers with the
name of the company that follows it three characters later.  Thus, the
above snipet will become:

<option value="Bain & Company">Bain & Company

<option value="Baker & Botts">Baker & Botts

<option value="Baker & McKenzie">Baker & McKenzie

Doing it by hand is an incredible pain as there are 5,000 entries.  Any
neat Perl solutions?


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


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

Date: Sat, 13 Nov 1999 23:51:34 GMT
From: kc@disinfo.net (Viscano)
Subject: Re: Weekday in perl
Message-Id: <382df959.15549087@news.idt.net>

>And the whole thing really doesn't do much more than
>
>use POSIX;
>print strftime "%a", localtime;

damn thats news to me =)
lol, sorry about the typo.





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

Date: 14 Nov 1999 00:28:47 GMT
From: mgjv@wobbie.heliotrope.home (Martien Verbruggen)
Subject: Re: What module for adding messages to mail folders?
Message-Id: <slrn82s0je.igg.mgjv@wobbie.heliotrope.home>

On 13 Nov 1999 12:14:14 -0800,
	Robert Nicholson <steffi@shell8.ba.best.com> wrote:
> I going to assume CPAN is out of date.

It's not. CPAN is hardly ever out of date. If it is, it's the module's
author's fault, not CPAN's.

What I don't understand is _why_ you assume it is...

> is Mail::Folder the way to go if you want to safely add email messages
> to mail folders?

What sort of Mail folders are you talking about? And have you read the
manual pages for Mail::Folder to find out if it does what you need it
to? Just download the archives from CPAN, extract, and read. Without any
more information than you give us, we can't sensibly advise anything.
But if you just want to append messages to mail folders, you might not
need it.
Besides that Mail::Folders is alpha, and its readme contains things
like:

WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING! WARNING!
Think twice about using this module to modify folders you consider
important.  At the very least make sure you have backup copies.

your choice.

A simple open for append, print, close, possibly with appropriate
locking could be just as appropriate. But you don't tell us what you
want to do, so it's hard to give advice.

I do use Mail::Folder somewhere in some scripts, but none of that is
business critical, and none of the data can't be recovered from other
sources, in case of catastrophe.

> What about GBARRs Mail::Util?

Graham's mail utilities are definitely a good choice.  I don't think
there's much in the way of mailbox handling in there though, IIRC it's
more message oriented.  But if you want Mail::Folder, it requires
MailTools anyway.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | That's not a lie, it's a
Commercial Dynamics Pty. Ltd.   | terminological inexactitude.
NSW, Australia                  | 


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

Date: Sun, 14 Nov 1999 00:08:48 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Which browser?
Message-Id: <k4nX3.8183$YI2.326370@typ11.nn.bcandid.com>

In article <382DEA9D.4664A2E0@wix.dk>, Christian Wix  <christian@wix.dk> wrote:
>How can I determine which browser people are using when they visit my
>my web page? The web page is private so the visitors are filling out a
>form (user name/password) when they login and the data is stored with
>post/QUERY_STRING. So can I automatically pass the browser information
>with "post" or can perl receive itself? How do I do it?

Wrong newsgroup.  $ENV{HTTP_USER_AGENT}.
-- 
<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>


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

Date: 13 Nov 1999 19:11:23 -0500
From: Scott Lanning <slanning@bu.edu>
Subject: Re: Which browser?
Message-Id: <kusu2mqaq50.fsf@strange.bu.edu>

Christian Wix <christian@wix.dk> writes:
> How can I determine which browser people are using when they
> visit my my web page?

Will u go with me (y or n)?

-- 
qualification: I'm a dimwit according to someone who emailed me


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

Date: Sun, 14 Nov 1999 00:06:12 GMT
From: kragen@dnaco.net (Kragen Sitaker)
Subject: Re: Writing data to file on another server.
Message-Id: <U1nX3.8176$YI2.325914@typ11.nn.bcandid.com>

In article <01bf2d94$31d33c00$c534d8c0@default>,
Crawfishy <cans1@hotmail.com> wrote:
>OK, I just spent the last 3 hours researching this and I think I have a
>handle on it.... But just so I don't beat my head against the wall for a
>week, let me just be sure...
>If I understand correctly, instead of using OPEN and PRINT to write data to
>a file as I am doing now, Instead I would create a routine that utilized
>the http::request using the PUT method. Correct?

Well, maybe.  If your web server supports PUT.  You might be better off
using a CGI script on the destination server to modify data.db -- you
can invoke said CGI script with a POST request from your original
machine.

>If this is correct, then will I need to have anything special on the
>receiving site to accept this PUT data.

At least set up authentication; probably you'll have to do something to
support PUT as well.  (mod_webdav for Apache?)

> Bear in mind that the receiving
>site is just going to be running a simple web server program over a static
>IP on Win98 not something "web advanced" like Linux.

Apache runs on both -- it's just less stable and mature on Winxx platforms.
-- 
<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>


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

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


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