[19170] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1365 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 24 06:10:36 2001

Date: Tue, 24 Jul 2001 03:10:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <995969417-v10-i1365@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 24 Jul 2001     Volume: 10 Number: 1365

Today's topics:
        newbie question about arrays <lupine925@hotmail.com>
    Re: newbie question about arrays (Eric Bohlman)
    Re: newbie question about arrays <godzilla@stomp.stomp.tokyo>
    Re: newbie question about arrays <krahnj@acm.org>
    Re: newbie: storing multiple objects in a hash (Randal L. Schwartz)
    Re: Open files <dbe@wgn.net>
    Re: print "Content-type: image/gif\n\n" and then??? <pne-news-20010724@newton.digitalspace.net>
    Re: print "Content-type: image/gif\n\n" and then??? nobull@mail.com
    Re: print "Content-type: image/gif\n\n" and then??? <flavell@mail.cern.ch>
    Re: Redirecting STDERR <dbe@wgn.net>
    Re: Remote updating of my website <dbe@wgn.net>
        Running the same scripts of different platforms <nomail@hursley.ibm.com>
    Re: Running the same scripts of different platforms <pmonsch@saint-etienne.tt.slb.com>
        scope for recursive sub <lapenta_jm@yahoo.com>
    Re: scope for recursive sub <ayamanita.nospam@bigfoot.com>
    Re: Sendmail with Win32 <dbe@wgn.net>
    Re: Sorting an array of strings by 'closeness' to anoth <jpixton@dircon.co.uk>
    Re: Split Question (Eric Bohlman)
        Splitting Peculiar HTML (Bill Atkins)
    Re: Splitting Peculiar HTML <godzilla@stomp.stomp.tokyo>
    Re: Splitting Peculiar HTML (Logan Shaw)
    Re: Splitting Peculiar HTML <Tassilo.Parseval@post.rwth-aachen.de>
        string extraction (shaz)
    Re: Upgrade Perl on RH7.1 From Source (Kevin der Kinderen)
    Re: use attributes; subs : lvalue { return $this->{anyv (Anno Siegel)
    Re: use CGI qw(:standard) <ayamanita.nospam@bigfoot.com>
    Re: use CGI qw(:standard) <mbudash@sonic.net>
        variable interpolation in mail::sendmail module? (Jon Andrew)
        What am I doing wrong? Help. <me@nospam.net>
    Re: What am I doing wrong? Help. <james@zephyr.org.uk>
    Re: What am I doing wrong? Help. <me@nospam.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Tue, 24 Jul 2001 02:04:41 GMT
From: Lup <lupine925@hotmail.com>
Subject: newbie question about arrays
Message-Id: <Xns90E7E08E89175lupine925hotmailcom@65.32.3.253>

Ok, plain and simple!

Easiest way to do this.

I apologize in adv for such a question, but this is what I need to do.
I have a file ($hostfile) , which is just a list of IPs.  I have another 
file ($usersfile) with the another list of IPs, but with more information 
"tabbed" after each IP (i.e. the corresponding UserName, ComputerName, 
etc.).  I have to generate a report for my network that will basically open 
the first file/array (@host_array), start with the first IP in the list, 
open the second file/array (@users_array) and find the matching IP, and 
finally print that line, (the corresponding UserName, ComputerName, etc.) to 
a report.  Whew!!!

This is what I have so far, and obviously it is not working.  It produces no 
results.


#--------------------------------------------------------------------------
$clrscrn = "cls" ;
system($clrscrn) ;

print "What file contains the list of users?", "\n" ;
$usersfile = <STDIN> ;
print "What file contains the IP you want to search for?", "\n" ;
$hostfile = <STDIN> ;
open (HOSTFILE,"$hostfile") || die "Could not find $host file." ;
open (USERSFILE,"$usersfile") || die "Could not find $usersfile." ;
@user_array = <USERSFILE> ;
@host_array = <HOSTFILE> ;
foreach $user (@user_array)
  {
  foreach $host (@host_array)
    {
    if ($user =~ /$host/)
      {
        print "$user" ;
      }
    }
  }
#--------------------------------------------------------------------------

TIA, 
Lup


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

Date: 24 Jul 2001 03:00:35 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: newbie question about arrays
Message-Id: <9jiocj$d1t$1@bob.news.rcn.net>

Lup <lupine925@hotmail.com> wrote:
> I apologize in adv for such a question, but this is what I need to do.
> I have a file ($hostfile) , which is just a list of IPs.  I have another 
> file ($usersfile) with the another list of IPs, but with more information 
> "tabbed" after each IP (i.e. the corresponding UserName, ComputerName, 
> etc.).  I have to generate a report for my network that will basically open 
> the first file/array (@host_array), start with the first IP in the list, 
> open the second file/array (@users_array) and find the matching IP, and 
> finally print that line, (the corresponding UserName, ComputerName, etc.) to 
> a report.  Whew!!!

This is called a "relational join" (as you might guess, a lot of the code 
in a relational database manager is devoted to doing things like this 
efficiently).

In general, you do *not* want to loop over the entire second file/array 
for each entry in the first file/array; this gets very slow very fast 
because the number of iterations equals the product of the two array 
sizes.  Rather, you should loop through the second file/array once, 
populating a hash keyed on the IP number, and then loop through the first 
file once, looking up each IP number in the hash.  This limits your 
iterations to the *sum* of the two sizes, which is usually going to be 
*much* smaller.

> This is what I have so far, and obviously it is not working.  It produces no 
> results.


> #--------------------------------------------------------------------------
> $clrscrn = "cls" ;
> system($clrscrn) ;

> print "What file contains the list of users?", "\n" ;
> $usersfile = <STDIN> ;
> print "What file contains the IP you want to search for?", "\n" ;
> $hostfile = <STDIN> ;
> open (HOSTFILE,"$hostfile") || die "Could not find $host file." ;
> open (USERSFILE,"$usersfile") || die "Could not find $usersfile." ;

These opens will most likely fail because you never chomp()'d your input 
and you probably don't have files with names that end in newlines.  Your 
error messages should include $! to indicate *why* the files couldn't be 
opened; note that "Could not find" is misleading since the reason for the 
failure to open might be something like lack of permissions.

> @user_array = <USERSFILE> ;
> @host_array = <HOSTFILE> ;

> foreach $user (@user_array)
>   {
>   foreach $host (@host_array)
>     {
>     if ($user =~ /$host/)

Since you didn't chomp() either input, $host will have a trailing newline 
and this will match only if the IP number in $user is the very last thing 
on the line (since $user will also have a trailing newline).

>       {
>         print "$user" ;

Useless use of double quotes.

>       }
>     }
>   }


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

Date: Mon, 23 Jul 2001 21:15:51 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: newbie question about arrays
Message-Id: <3B5CF677.F0E4D52D@stomp.stomp.tokyo>

Lup wrote:

(snipped)
 
> Easiest way to do this.

There is a distinct difference between easy
and efficient. You are also ignoring Perl
allows many ways to accomplish a given task.

 
> I apologize in adv for such a question,

Are you apologizing in adverb or in advance?

If your article motivates you to apologize in
advance, consider rewording your article or not
posting; something is not right.


> I have a file ($hostfile) , which is just a list of IPs.  I have another
> file ($usersfile) with the another list of IPs, but with more information
> "tabbed" after each IP (i.e. the corresponding UserName, ComputerName,
> etc.).  I have to generate a report for my network that will basically open
> the first file/array (@host_array), start with the first IP in the list,
> open the second file/array (@users_array) and find the matching IP, and
> finally print that line, (the corresponding UserName, ComputerName, etc.) to
> a report.


As indicated, there are many ways to do this. I have tossed
together a five minute test script, a twelve line script although
some regulars here claim a Perl programmer can only produce
ten lines of code per day. This test script of mine makes use
of quick and efficient substr () and index () while only using
one array loop mechanism.

Your parameters are, paraphrased,

One array containing only ip addresses.
One associative array containing ip addresses associated with other data.

Your parameters are somewhat lacking but not beyond logical
presumptions. A presumption is made all users have a static
ip address rather than dynamic. Another presumption is your
first array consists of ip logon events and you wish to
identify these addresses by user name and other data.

* wonders why you don't simply parse your server logs *

My test script contains short versions of your parameters;
an array of ip addresses and an associative array of users.

Logic is to create a string, $ip_address , using the list
of ip addresses contained in @Array_1 then employ a single
loop which indexes this string with a substring generated
ip address. If the index is positive, selected user data
within my associative array is simply printed. 

Quick, clean and simple, yes?


Godzilla!
--

TEST SCRIPT:
____________

#!perl

print "Content-type: text/plain\n\n";

@Array_1 = qw (123.123 123.234 123.345 123.456);

@Array_2 = ("234.123 Lucy Lawless", "123.234 Susan Anton", "123.456 Joan Of Arc");

$ip_address = "@Array_1";

for (@Array_2)
 {
  $user_ip = substr ($_, 0, index ($_, " "));
  if (index ($ip_address, $user_ip) > -1)
   { print "$_\n"; }
 }

exit;

PRINTED RESULTS:
________________

123.234 Susan Anton
123.456 Joan Of Arc


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

Date: Tue, 24 Jul 2001 05:36:03 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: newbie question about arrays
Message-Id: <3B5D0940.50AECBD0@acm.org>

Lup wrote:
> 
> Ok, plain and simple!
> 
> Easiest way to do this.
> 
> I apologize in adv for such a question, but this is what I need to do.
> I have a file ($hostfile) , which is just a list of IPs.  I have another
> file ($usersfile) with the another list of IPs, but with more information
> "tabbed" after each IP (i.e. the corresponding UserName, ComputerName,
> etc.).  I have to generate a report for my network that will basically open
> the first file/array (@host_array), start with the first IP in the list,
> open the second file/array (@users_array) and find the matching IP, and
> finally print that line, (the corresponding UserName, ComputerName, etc.) to
> a report.  Whew!!!
> 
> This is what I have so far, and obviously it is not working.  It produces no
> results.
> 
> #--------------------------------------------------------------------------
#!/usr/bin/perl -w
use strict;

> $clrscrn = "cls" ;

my $clrscrn = 'cls';

> system($clrscrn) ;
> 
> print "What file contains the list of users?", "\n" ;
> $usersfile = <STDIN> ;

print "What file contains the list of users?\n";
chomp( my $usersfile = <STDIN> );

> print "What file contains the IP you want to search for?", "\n" ;
> $hostfile = <STDIN> ;

print "What file contains the IP you want to search for?\n";
chomp( my $hostfile = <STDIN> );

> open (HOSTFILE,"$hostfile") || die "Could not find $host file." ;
> open (USERSFILE,"$usersfile") || die "Could not find $usersfile." ;
> @user_array = <USERSFILE> ;
> @host_array = <HOSTFILE> ;

my %host_lookup;
open HOSTFILE, $hostfile or die "Could not open $host file. $!";
{
chomp( my @host_array = <HOSTFILE> );
@host_lookup{@host_array} = ();
}
open USERSFILE, $usersfile or die "Could not open $usersfile. $!";


> foreach $user (@user_array)
>   {
>   foreach $host (@host_array)
>     {
>     if ($user =~ /$host/)
>       {
>         print "$user" ;
>       }
>     }
>   }

while ( <USERSFILE> ) {
    print if exists $host_lookup{ (split /\t/)[0] };
    }



John
-- 
use Perl;
program
fulfillment


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

Date: 23 Jul 2001 19:53:19 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: newbie: storing multiple objects in a hash
Message-Id: <m1wv4zkpgg.fsf@halfdome.holdit.com>

>>>>> "Logan" == Logan Shaw <logan@cs.utexas.edu> writes:

Logan> However, you can store a list of hashes.  Think of it as doing this:

Logan> 	$user1{name} = "John Doe";
Logan> 	$user1{email} = "jdoe@hotmail.com";
Logan> 	$user2{name} = "Bert Smith";
Logan> 	$user2{email} = "bsmith@netscape.com";

Not really.  You want \@ or '' there. :)

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


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

Date: Tue, 24 Jul 2001 01:18:27 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Open files
Message-Id: <3B5D2F53.A3FCE776@wgn.net>

Rob Kirby wrote:
> 
> I would like to use the Find.pm to traverse a filesystem to create
> a list of files that reside in that filesystem and record various
> info about each file with the stat.pm module. Is there a module
> to obtain a list of open files for a given filesystem?

File::Find

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Tue, 24 Jul 2001 07:35:43 +0200
From: Philip Newton <pne-news-20010724@newton.digitalspace.net>
Subject: Re: print "Content-type: image/gif\n\n" and then???
Message-Id: <ro1qlt00oibcl05c0b3k0dvissau8c6c6f@4ax.com>

On 23 Jul 2001 04:01:59 -0700, selfesteem@virgilio.it (Caribe1999)
wrote:

> If I want to send to the browser only a image, without HTML code, what
> must I send after this string?

The binary image data. Which you could have in a string, or (more
likely) read from a file or generate with a module.

If you're advertising "image/gif", then of course the image data must be
in GIF (e.g. match /^GIF8[79]a/).

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
That really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: 24 Jul 2001 08:55:14 +0100
From: nobull@mail.com
Subject: Re: print "Content-type: image/gif\n\n" and then???
Message-Id: <u9zo9uohs8.fsf@wcl-l.bham.ac.uk>

selfesteem@virgilio.it (Caribe1999) writes:

> If I want to send to the browser only a image, without HTML code, what
> must I send after this string?

A GIF image.

Now, did you have a Perl question?

-- 
     \\   ( )
  .  _\\__[oo
 .__/  \\ /\@
 .  l___\\
  # ll  l\\
 ###LL  LL\\


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

Date: Tue, 24 Jul 2001 10:50:19 +0200
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: print "Content-type: image/gif\n\n" and then???
Message-Id: <Pine.LNX.4.30.0107241049410.9410-100000@lxplus023.cern.ch>

On Jul 24, nobull@mail.com eloquently disturbed the ether:

> > If I want to send to the browser only a image, without HTML code, what
> > must I send after this string?
>
> A GIF image.
>
> Now, did you have a Perl question?

The answer will be binmode()   ;-)




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

Date: Tue, 24 Jul 2001 00:29:28 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Redirecting STDERR
Message-Id: <3B5D23D8.3CD55EF6@wgn.net>

"MMX166+2.1G HD" wrote:
> 
> I try it on my win98se machine, and it dosen't work :(

You can either get ahold of cmd.exe or redirect STDERR to STDOUT 
in your script before running the command.

I believe I have a cmd.exe on my Webjump site (no warranties).

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Tue, 24 Jul 2001 00:46:43 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Remote updating of my website
Message-Id: <3B5D27E3.4BA320F3@wgn.net>

Simon Marshall - SMA wrote:
> 
> Before you suggest linking a mobile to a laptop and
> doing it via html & ftp,
> what I want to do is send the emails from my mobile
> phone and keep it
> simple.
> 
> Any ideas? My service provider is clara.net if that's
> of any help.

From your mobile phone can you log into your ISP and surf the web ?

If so, it's much easier to surf to a form and fill in a text 
box and have a CGI script update an HTML page.  That would 
be keeping it simple in comparison to using email.  A simple 
bulletin board script with basic authentication protecting 
others from using it would be simple.

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Tue, 24 Jul 2001 08:35:07 +0100
From: Derek Fountain <nomail@hursley.ibm.com>
Subject: Running the same scripts of different platforms
Message-Id: <9jj8fc$o2m$1@sp15at20.hursley.ibm.com>

I have a number of scripts which are designed to run on either Linux or 
AIX. What is the best way to make a platform independent she-bang line? The 
Perl on the Linux boxes is /usr/bin/perl, while on the AIX machines it's in 
a special directory in our AFS filesystem. I have no say in what goes into 
/usr/bin on the AIX machines.




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

Date: Tue, 24 Jul 2001 11:05:04 +0200
From: Pascal Monschein <pmonsch@saint-etienne.tt.slb.com>
To: Derek Fountain <nomail@hursley.ibm.com>
Subject: Re: Running the same scripts of different platforms
Message-Id: <3B5D3A40.C09515F4@saint-etienne.tt.slb.com>

Derek Fountain wrote:

> I have a number of scripts which are designed to run on either Linux or
> AIX. What is the best way to make a platform independent she-bang line? The
> Perl on the Linux boxes is /usr/bin/perl, while on the AIX machines it's in
> a special directory in our AFS filesystem. I have no say in what goes into
> /usr/bin on the AIX machines.

--> Method 1 :
#!/usr/bin/env perl
  "perl" should be in your path variable and  is "/usr/bin/env" always true ?
that I am not sure.

--> Method 2 :
         #!/bin/sh -- # -*- perl -*- -p
         eval 'exec perl -wS $0 ${1+"$@"}'
             if $running_under_some_shell;

The above section has been taken from the perl documentation by running :
"perldoc perlrun"


Pascal



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

Date: Mon, 23 Jul 2001 21:08:29 -0400
From: Jason LaPenta <lapenta_jm@yahoo.com>
Subject: scope for recursive sub
Message-Id: <3B5CCA8D.C410D0DC@yahoo.com>

Hello,

I have a recursive sub. and I want a local var that is not global, so
each call in the recursion has it's own copy. How do I do this. I've
tried delcaring it local.

thanks
Jason


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

Date: Tue, 24 Jul 2001 01:31:59 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: scope for recursive sub
Message-Id: <3B5CCFFD.2DC0F3C1@bigfoot.com>

Jason LaPenta wrote:
> 
> I have a recursive sub. and I want a local var that is not global, so
> each call in the recursion has it's own copy. How do I do this. I've
> tried delcaring it local.

Use my instead of local.


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

Date: Tue, 24 Jul 2001 01:12:11 -0700
From: "$Bill Luebkert" <dbe@wgn.net>
Subject: Re: Sendmail with Win32
Message-Id: <3B5D2DDB.33A4927E@wgn.net>

Jeff Hill wrote:
> 
> First, before anyone flames me, I know this is off subject, but I felt
> that this community was much more likely to have someone who has
> encountered this situation than the Windows NT community (since most
> hardcore MS users wouldn't know a Unix box if it hit them upside the
> head).
> 
> What I would like to know is if anyone knows of a sendmail utility
> that works on Windows NT with Exchange server.  The reason I'd like to
> use a sendmail compatible program is for portability.
> 
> I have a large number of Perl scripts on a Unix platform that notify
> me by e-mail when there is a problem.  I'd like to use some of them in
> an NT/IIS environment without having to do a lot of reconfiguring my
> scripts.

I would use MIME::Lite (set it to use SMTP if on Win32).

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   Mailto:dbe@todbe.com 
  / ) /--<  o // //      http://dbecoll.webjump.com/ (Free site for Perl)
-/-' /___/_<_</_</_     Castle of Medieval Myth & Magic http://www.todbe.com/


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

Date: Tue, 24 Jul 2001 09:20:43 +0100
From: jbp <jpixton@dircon.co.uk>
Subject: Re: Sorting an array of strings by 'closeness' to another string
Message-Id: <kjbqlt0lc13g3cmcqgjfmuf9ckeckgukin@4ax.com>

At 23 Jul 2001 17:36:05 -0500, Logan Shaw said:
>In article <f06plts0n3rdpig7u2moer3b7ess0s9e52@4ax.com>,
>jbp  <jpixton@dircon.co.uk> wrote:
>>Howdy
>>
>>I have a string containing, say, 'transeint' (sic). After some
>>massaging the string a little, then grepping a dictionary, then some
>>more massaging, i get an array of strings like so:
>>
>>anastasia
>>anisettes
>>anteaters
>>assassins
>>assistant
>>easterner
>  :
>  :
>>testiness
>>transient
>>treatises
>>trinities
>>triteness
>>
>>Now, what I want to do is sort this array into an order such that the
>>ones near the top of the array (viewing it as a stack) are:
>>
>>transient
>>treatises
>>trinities
>>... etc
>
>If you're going to sort in the traditional sense, then you have to have
>a function that can always compare two items and tell you which one
>comes first.  In other words, you have to have an ordering defined.
>In other other words, I'm not sure what you're trying to accomplish.

I know I can do something like

  @array = sort {myfunc($a) <=> myfunc($b)} @array;

But the problem is making a myfunc which acheives the result I want (a
string sorted with minimum spanning-distance first). 

>>How would I go about this? I've looked at String::Approx and one of
>>the functions would be ideal, except I can't install the module on my
>>host (the goddamn service provider won't do it).
>
>"The service provider won't" and "I can't" aren't equivalent,
>especially if you can login to the web server.

Is it possible to install modules with only ftp access? If so, how?
This would fix my problem immediately :)

Thanks for any help :)

-- 
Joseph Birr-Pixton .:|:. http://ifihada.com .:|:. ICQ#40675236
Interdum feror cupidine partium magnarum Europae vincendarum.


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

Date: 24 Jul 2001 02:18:17 GMT
From: ebohlman@omsdev.com (Eric Bohlman)
Subject: Re: Split Question
Message-Id: <9jilt9$bud$3@bob.news.rcn.net>

Mark Riehl <mark.riehl@agilecommunications.com> wrote:
> All - I'm trying to parse a CSV file (that originated as an Excel file),
> here's a sample line:

> VALID,,102, 1051,2001-04-03 17:22:00.36,2001-04-03 17:22:00.36,... (total of
> 42 records per line).  I'm really interested in only the first 10 fields per
> line.

> and I'm using the following line to split it up:

> @array = split(',', $_);

> However, some of the lines in second field contain comments that contain
> newlines like this:

> VALID,TEXT HERE\n ANOTHER LINE OF COMMENT\n,102, 1051,2001-04-03
> 17:22:00.36,2001-04-03 17:22:00.36,...

> It appears that the split is stopping on these premature newlines, and
> getting confused.

split doesn't have a problem with newlines.  However, if you're reading 
the file line-by-line, you're only reading up to the first newline each 
time, so naturally split won't have the whole record to work on.  You're 
going to have to figure out some way to determine when you've got a whole 
record before splitting it.  If (and this is a *big* if), none of your 
fields can contain embedded commas, you could do something like:

while (<INPUT>) {
  chomp;
  while (tr/,// < 41) {
    $_ .= <INPUT>;
    chomp;
  }
  my @array = split(/,/,$_);
# process the fields
}

Note that this will go into an infinite loop if the last record is 
incomplete.




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

Date: 23 Jul 2001 18:52:11 -0700
From: billatkins@bigfoot.com (Bill Atkins)
Subject: Splitting Peculiar HTML
Message-Id: <60805a5e.0107231752.34ae92a9@posting.google.com>

Given the following HTML code:

gtgtgtgtgtgtgtgtgtaaaag<font
color="blue">acacggc</font>aattaatatcgtggcgagaccttctctctttcttttaccgctcccggggtcctcctcaattcatccgctcctcgagacgaagacgtcgacacaatcggtgtttatttttgcgacgtagggcaattttactcgcaaacatatgagaggggaggcgccgacgacacccgggcgggcggcctgacgagaggtttagatagcgggggaaatagagaagttggaatgaagcggctgctattgctgccaccgcacggcaagaagcggacacaattcaacccgaagatattttttatgtgcacctagatgaactctttttgcaaaacctctcaattagtagacctttgaaactcaacaacgtttggacgaacctaacttg
caccgccgcctttttctctaatcttatctgatgaaacagaacatctgatgttatcacaatcaatcaaatcttattcatctctacgaattcgtaaatgttttcacttacatataaattggaagaaaaacggattatcgttccagagatcaaaaaatgatgtgcctccccttttttgcaattaatcctcaactcgtatttctctttgtatgtcttgaaaattgaaatttagacagtttagttgttatcacgtcagttttgtgtattccacttgaactatctatctggttggttagtctcctcccacccatgagtctt<b>tcatttatgtttg</b>tctagcctgacaattgacctgaccaccaaccatcaggtctctcccacgttttgtatttttattat
cacattacgaactgtgtgaaaatggctg

is there any way to divide the text into groups of ten without
including the HTML tags?  For instance, the result would be:

<font color="blue">agggg</font>cgagc cgagcgcagt tgcacgtacc ttgccaaaag
 ...

Any help would be appreciated.

Bill


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

Date: Mon, 23 Jul 2001 19:29:53 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Splitting Peculiar HTML
Message-Id: <3B5CDDA1.9CF2290B@stomp.stomp.tokyo>

Bill Atkins wrote:
 
> Given the following HTML code:

(snipped)

> is there any way to divide the text into groups of ten without
> including the HTML tags?  For instance, the result would be:
 
> <font color="blue">agggg</font>cgagc cgagcgcagt tgcacgtacc ttgccaaaag

> Any help would be appreciated.


Here is some help. You have contradicted yourself
within the same breath. You say you want html tags 
removed, then cite an example displaying html 
tags. Consider resolving your confusion, then
write and post a coherent article.


Godzilla!


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

Date: 24 Jul 2001 00:12:28 -0500
From: logan@cs.utexas.edu (Logan Shaw)
Subject: Re: Splitting Peculiar HTML
Message-Id: <9jj03s$400$1@charity.cs.utexas.edu>

In article <60805a5e.0107231752.34ae92a9@posting.google.com>,
Bill Atkins <billatkins@bigfoot.com> wrote:
>Given the following HTML code:
>
>gtgtgtgtgtgtgtgtgtaaaag<font
>color="blue">acacggc</font>aattaatatcgtggcgagaccttctctctttcttttaccgctcccggggtcctcctcaattcatccgctcctcgagacgaagacgtcgacacaatcggtgtttatttttgcgacgtagggcaattttactcgcaaacatatgagaggggaggcgccgacgacacccgggcgggcggcctgacgagaggtttagatagcgggggaaatagagaagttggaatgaagcggctgctattgctgccaccgcacggcaagaagcggacacaattcaacccgaagatattttttatgtgcacctagatgaactctttttgcaaaacctctcaattagtagacctttgaaactcaacaacgtttggacgaacctaacttg
>caccgccgcctttttctctaatcttatctgatgaaacagaacatctgatgttatcacaatcaatcaaatcttattcatctctacgaattcgtaaatgttttcacttacatataaattggaagaaaaacggattatcgttccagagatcaaaaaatgatgtgcctccccttttttgcaattaatcctcaactcgtatttctctttgtatgtcttgaaaattgaaatttagacagtttagttgttatcacgtcagttttgtgtattccacttgaactatctatctggttggttagtctcctcccacccatgagtctt<b>tcatttatgtttg</b>tctagcctgacaattgacctgaccaccaaccatcaggtctctcccacgttttgtatttttattat
>cacattacgaactgtgtgaaaatggctg
>
>is there any way to divide the text into groups of ten without
>including the HTML tags?  For instance, the result would be:
>
><font color="blue">agggg</font>cgagc cgagcgcagt tgcacgtacc ttgccaaaag
>...

I would probably go with the HTML::SimpleParse module.  It can take an
HTML file and break it up into a list of tags and non-tags.  That sort
of solves half the problem.

However, one problem with your task as specified is that you can't
consider each part of the text as separate.  That makes things
more difficult because you can't just use a regular expression on
each string; they all need to be considered in context.

I personally would just ignore regular expressions and write a simple
loop that reads characters from a series of strings, remembering many
characters it has seen since it last inserted a space.

  - Logan
-- 
"Our grandkids love that we get Roadrunner and digital cable."
(Advertisement for Time Warner cable TV and internet access, July 2001)


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

Date: Tue, 24 Jul 2001 11:00:40 +0200
From: Tassilo von Parseval <Tassilo.Parseval@post.rwth-aachen.de>
Subject: Re: Splitting Peculiar HTML
Message-Id: <3B5D3938.9040406@post.rwth-aachen.de>

Godzilla! wrote:

>Bill Atkins wrote:
> 
>
>>is there any way to divide the text into groups of ten without
>>including the HTML tags?  For instance, the result would be:
>>
> 
>
>><font color="blue">agggg</font>cgagc cgagcgcagt tgcacgtacc ttgccaaa
>>
>
>Here is some help. You have contradicted yourself
>within the same breath. You say you want html tags 
>removed, then cite an example displaying html 
>tags. Consider resolving your confusion, then
>write and post a coherent article.
>
No, he has not. He does not want the html-tags to be removed. Instead he 
wants to skip html-tags when making the groups of ten.
I am not yet sure, Godzilla!. but reading your replies here makes me 
wonder whether you prefer to help people or implicitely insult them.

Tassilo

-- 
The correct way to punctuate a sentence that starts: "Of course it is none
of my business, but --" is to place a period after the word "but."  Don't use
excessive force in supplying such a moron with a period.  Cutting his throat
is only a momentary pleasure and is bound to get you talked about.
		-- Lazarus Long, "Time Enough for Love"




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

Date: 23 Jul 2001 18:37:33 -0700
From: ssa1701@yahoo.co.uk (shaz)
Subject: string extraction
Message-Id: <23e71812.0107231737.7ef2ba6d@posting.google.com>

Does anyone know how to go about extracting keywords from text files?
The following code only finds some words in the text file but does not
show the no of occurances of each word.

I'll get the answer after a while but i would appriecate a little
help. The file is:-

#!/usr/bin/perl -w
print "Enter the name of the word file, including extension: "; 

$file=<STDIN>;
chomp $file;

open(W, "$file") || die "Cannot open wordfile: $!";
@lines=<W>;
close(W);

foreach(@lines) 
{
  if (/\w\s<NN>/g) 
  {
    print "$_";
  }

  if (/\w\s<VBZ>/g) 
  {
    print "$_";
  }
}


The word file is:-

This is part of Sol05a.txt and also the final report <NN>. This is
used for eegggtgg the book <NN>.

hello <VBZ>
bye
computer<NN>
printer
table <VBZ>
monitor <NN>
explorer <NN>
thoughts


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

Date: 24 Jul 2001 02:01:23 -0700
From: kevin@parr.net (Kevin der Kinderen)
Subject: Re: Upgrade Perl on RH7.1 From Source
Message-Id: <6e6452ff.0107240101.10257d9f@posting.google.com>

I think I solved my problem. When configuring 5.6.1 I said use
previous modules from 5.6.0. When I rebuilt it I said no. So far seems
to be working fine.

I never uninstalled the rh perl rpms because of all the dependencies -
so I don't know if that will cause problems down the road.

Still wondering what the right way to do this would have been.

Tks,
K


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

Date: 24 Jul 2001 08:38:59 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: use attributes; subs : lvalue { return $this->{anyvar} } question
Message-Id: <9jjc73$jno$1@mamenchi.zrz.TU-Berlin.DE>

According to Ilya Martynov  <ilya@martynov.org>:
> 
> MU> I want to create attribute handlers which could be written like:
> MU> $this->name = 'Murat';
> 
> MU> The perlsub.pod states i can "use attributes" with attribute : lvalue for
> MU> this:
> 
> MU> __START__
> 
> MU> package Foo;
> 
> MU> sub name : lvalue
> MU> {
> MU>    my $this = shift;
> 
> MU> return @_ ? $this->{name} = shift : $this->{name};
>     ^^^^^^
> 
> Remove 'return'. I've not idea why it helps but it does helps.

It helps because of a bug: lvalue doesn't work well with explicit
return.  The code should have "worked" as given, but the lvalue
routine is still incorrectly written.

The conditional code "@_ ? $this->{name} = shift : $this->{name};"
is typical for accessor methods that are *not* lvalue methods.
It assumes that a new value for "name", if any, is given as a
parameter in the call, as in "$obj->name( 'Another Name')", and
acts accordingly.  But the OP wants to call the method as
"$obj->name = 'Another Name'".  Here no parameter is given and
@_ in the conditional will always be empty.  So the conditional
reduces to "$this->{ name}", the other possibility with the
explicit assignment is never used.

The correct way to write this is much simpler:

    sub name : lvalue {
        my $this = shift;
        $this->{ name};
    }

That is, you simply return what you (potentially) want to assign
to; the syntax of the call does the rest.
 
[snip]

Anno


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

Date: Tue, 24 Jul 2001 03:05:30 GMT
From: Akira Yamanita <ayamanita.nospam@bigfoot.com>
Subject: Re: use CGI qw(:standard)
Message-Id: <3B5CE5E8.A8EC16DB@bigfoot.com>

Todd Anderson wrote:
> 
> Dear Peoples,
> I am using "use CGI qw(:standard);" In the past when using cgi-lib.pl I
> could do this...
>  $form_data{'pagename'} = $form_data('glockenspider');
> When I try it with "CGI" I use this...
>  param('pagename') = param('glockenspider');
> But this doesn't work... Any ideas are appreciated. Thanks in advance
> for your help

You're trying to assign a value to a sub routine. Dump the data
into a hash.

#!/usr/bin/perl
use CGI qw(:standard);

foreach $key(param) {
	$form_data{$key}=param($key);
	}

$form_data{'pagename'} = $form_data{'glockenspider'};


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

Date: Tue, 24 Jul 2001 04:34:58 GMT
From: Michael Budash <mbudash@sonic.net>
Subject: Re: use CGI qw(:standard)
Message-Id: <mbudash-489203.21350123072001@news.sonic.net>

In article <3B5C614E.13278F24@mrnoitall.com>, Todd Anderson 
<todd@mrnoitall.com> wrote:

> Dear Peoples,
> I am using "use CGI qw(:standard);" In the past when using cgi-lib.pl I
> could do this...
>  $form_data{'pagename'} = $form_data('glockenspider');
> When I try it with "CGI" I use this...
>  param('pagename') = param('glockenspider');
> But this doesn't work... Any ideas are appreciated. Thanks in advance
> for your help
> 
> 

param('pagename', param('glockenspider'));

see 'Setting The Value(s) Of A Named Parameter' at:

http://stein.cshl.org/WWW/software/CGI/

hth-
-- 
Michael Budash ~~~~~~~~~~ mbudash@sonic.net


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

Date: 24 Jul 2001 02:08:11 -0700
From: cheesey_rower@hotmail.com (Jon Andrew)
Subject: variable interpolation in mail::sendmail module?
Message-Id: <6018d4e1.0107240108.204f6ade@posting.google.com>

Hi I have the following code that is not working correctly. What
happens is that 
$content will print out fine the contents (e.g. "coname--appnam") but
as soon as it goes into sendmail all content of the $content var is
ignored, however, one of the appnames by mistake had a semi-colon at
the end and this did come through. So the var is being interpolated.
But it appears that the contents of the var are being stripped. The
weird thing is that I can print out $mail{body} and see the content of
the message but it never makes it through sendmail. Platform this is
running on is HP-UX if that makes a difference.

Please help - I have been pulling my hair out over this for three
days now!!

Jon


$sql1  = "select a.name, b.longcode from  fly_app_data a,
fly_comp_codes b WHERE update >= DATE ('$PARAMS{dat}') AND
a.companycode=b.companycode ORDER by b.longcode";
 @data=sql_data($dbh,$sql1);

#####mail content

use MIME::QuotedPrint;
use Mail::Sendmail;

for (@data){
  push(@body,$$_{1}.'--'.$$_{0});
  }

      
$content=join("",@body);


use MIME::QuotedPrint;
use Mail::Sendmail;

$text = "These have been "
 . "updated  $content" ;
$txtbody = encode_qp $text;
%mail = (
         SMTP => 'smtp.name.com',
         from => 'name@name.com',
         to => "$list",
         subject => 'ammendment accepted',
         body => 'text/plain; charset="iso-8859-1"',
        );
$mail{body} =$txtbody;


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

Date: Mon, 23 Jul 2001 22:56:01 -0500
From: "Jason Hunter" <me@nospam.net>
Subject: What am I doing wrong? Help.
Message-Id: <9jirms$b5f$1@slb3.atl.mindspring.net>

I am trying to send mail to a specific csr based on the state that was
selected in an HTML form.  This is based partly on the Formmail code from
MSA.  Here is the basic gist of my script:

I have a hash setup outside any of the subroutines, like so:

%csr_routing_data = (
'-' => 'default@test.com',
AL => 'AL@test.com',
AK => 'AK@test.com',
CO => 'CO@airborn.com')

Then in the parse_form subroutine:

sub parse_form {

    # Define the configuration associative array.
#
    %Config = ('recipient','',
     'email','',
  'required','E-Mail, State);

    #split the name-value pairs
    @pairs = split(/&/, $buffer);

    # For each name-value pair:
#
    foreach $pair (@pairs) {

        # Split the pair up into individual variables.
#
        local($name, $value) = split(/=/, $pair);

       if (defined($Config{$name})) {
            $Config{$name} = $value;
        }
        else {
            if ($Form{$name} && $value) {
                $Form{$name} = "$Form{$name}, $value";
            }
            elsif ($value) {
                push(@Field_Order,$name);
                $Form{$name} = $value;
            }
        }
    }
}

Now, how in the world do I get the recipient field filled in in the %Config
hash?  I need to populate that variable based on what was passed in in an
HTML form field named 'State'?  Sorry if this is easy, but I'm struggling
here.  I just keep getting the dreaded Internal 500 error.

Jason




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

Date: Tue, 24 Jul 2001 05:34:00 +0100
From: James Coupe <james@zephyr.org.uk>
Subject: Re: What am I doing wrong? Help.
Message-Id: <ryRahzC4qPX7Ewav@gratiano.zephyr.org.uk>

In message <9jirms$b5f$1@slb3.atl.mindspring.net>, Jason Hunter
<me@nospam.net> writes
>I am trying to send mail to a specific csr based on the state that was
>selected in an HTML form.  This is based partly on the Formmail code from
>MSA.

Quite simply, don't.  Matt's Script Archive is filled with so much Bad
Stuff (tm) that it's north worth picking it apart for even the germ of
any idea.  Really Bad Stuff.

(Slight re-shuffle.)

>Now, how in the world do I get the recipient field filled in in the %Config
>hash?

use CGI; # If you're a newbie, never roll your own CGI implementation
my $cgi;
$cgi = new CGI;
my $variable; # or wherever you want to store it
$variable = $cgi->param('State');

>  I need to populate that variable based on what was passed in in an
>HTML form field named 'State'?  Sorry if this is easy, but I'm struggling
>here.  I just keep getting the dreaded Internal 500 error.

That's because your script is broken.....

>sub parse_form {
>
>    # Define the configuration associative array.
>#
>    %Config = ('recipient','',
>     'email','',
>  'required','E-Mail, State);

 .... here.  Check your quotes.


-- 
James Coupe                                                PGP Key: 0x5D623D5D
        "Surely somewhere out there there's a woman who's        EBD690ECD7A1F
        been sodomized by her father and is capable of           B457CA213D7E6
        composing a few coherent sentences on the subject."     68C3695D623D5D


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

Date: Tue, 24 Jul 2001 00:17:55 -0500
From: "Jason Hunter" <me@nospam.net>
Subject: Re: What am I doing wrong? Help.
Message-Id: <9jj0gc$mr3$1@nntp9.atl.mindspring.net>

Thanks for the tip.  I thought MSA was a reliable place, but I guess that
just shows how new I am...;-)

The quote in the last section was simply a typo in my post, but not in the
code.

James Coupe wrote in message ...
>
>Quite simply, don't.  Matt's Script Archive is filled with so much Bad
>Stuff (tm) that it's north worth picking it apart for even the germ of
>any idea.  Really Bad Stuff.
>
>>  'required','E-Mail, State);
>
>.... here.  Check your quotes.
>




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

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


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