[22118] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4340 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Jan 4 03:05:38 2003

Date: Sat, 4 Jan 2003 00:05:06 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 4 Jan 2003     Volume: 10 Number: 4340

Today's topics:
    Re: conditional search and replace <member9705@dbforums.com>
    Re: conditional search and replace <goldbb2@earthlink.net>
        Damian Conway Perl Classes <uri@stemsystems.com>
        date string to date format (Djinn)
    Re: date string to date format <bwalton@rochester.rr.com>
    Re: date string to date format <tony_curtis32@yahoo.com>
    Re: Generating extra whitespace in for loop (Tad McClellan)
    Re: Generating extra whitespace in for loop <krahnj@acm.org>
    Re: how to load a module depending on 'if' condition ? <murat.uenalan@gmx.de>
        Multipart error sendmail <luyendyk@yahoo.com.news>
    Re: Multipart error sendmail (Malcolm Dew-Jones)
    Re: Need help with split <Jodyman@hotmail.com>
    Re: Need help with split <uri@stemsystems.com>
    Re: Need help with split <krahnj@acm.org>
    Re: Need help with split (Tad McClellan)
    Re: Newbie Reg. Exp. questions.. <truthxayer@yahoo.com>
    Re: Problem with huge dataset, 100000000 a magic number <krahnj@acm.org>
    Re: XS memory management <joe+usenet@sunstarsys.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 03 Jan 2003 09:06:41 +0000
From: Damian Ibbotson <member9705@dbforums.com>
Subject: Re: conditional search and replace
Message-Id: <2343048.1041584801@dbforums.com>


Cheers guys.

Out of curiosity...

Is there some kind of 'ifnull' construct I could use when attaining
values from a hashmap (as per my original attempt) or was I barking up
the wrong tree?

--
Posted via http://dbforums.com


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

Date: Fri, 03 Jan 2003 20:25:16 -0500
From: Benjamin Goldberg <goldbb2@earthlink.net>
Subject: Re: conditional search and replace
Message-Id: <3E1637FC.382E1FB3@earthlink.net>

Damian Ibbotson wrote:
> 
> Cheers guys.
> 
> Out of curiosity...
> 
> Is there some kind of 'ifnull' construct I could use when attaining
> values from a hashmap (as per my original attempt) or was I barking up
> the wrong tree?

I suppose you could, but it wouldn't be simple string interpolation, but
would have to be a full-fleged expression.

s/(^.{11})(.)(.)(.)(.)(.)(.)/
  $1 .
  (exists $tr1{$2} ? $tr1{$2} : $2) .
  (exists $tr1{$3} ? $tr1{$3} : $3) .
  (exists $tr2{$4} ? $tr2{$4} : $4) .
  (exists $tr2{$5} ? $tr2{$5} : $5) .
  (exists $tr2{$6} ? $tr2{$6} : $6) .
  (exists $tr2{$7} ? $tr2{$7} : $7)
/ge;

IMHO, this would be much better written as:

   substr( $_, 11, 2 ) =~ tr/OI/01/;
   substr( $_, 13, 4 ) =~ tr/OIZ/012/;

Certainly it will be faster.

PS: If you really want to use s///, consider:

   substr( $_, 11, 2 ) =~ s/([OI])/$tr1{$1}/g;
   substr( $_, 13, 4 ) =~ s/([OIZ])/$tr2{$1}/g;

-- 
$..='(?:(?{local$^C=$^C|'.(1<<$_).'})|)'for+a..4;
$..='(?{print+substr"\n !,$^C,1 if $^C<26})(?!)';
$.=~s'!'haktrsreltanPJ,r  coeueh"';BEGIN{${"\cH"}
|=(1<<21)}""=~$.;qw(Just another Perl hacker,\n);


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

Date: Sat, 04 Jan 2003 07:05:17 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Damian Conway Perl Classes
Message-Id: <x73co9xums.fsf@mail.sysarch.com>


For the past two summers, we have had the privilege of offering in
Boston, Perl classes taught by Damian Conway. The classes have been a
major success and we are happy that Damian is coming back to teach three
classes over four days in January, 2003.

We are bringing back the two day Advanced Object Oriented Perl class
that was so popular in July, 2001. This class is for anyone who wants to
take their OO Perl skills to the next level. Data Munging is being
offered here for the first time and it will cover highly practical ways
to process data in Perl. Parsing for Bioinformatics is very similar to
the popular Parsing with Perl class that Damian taught last summer but
all the examples presented in this course use the language, data sets,
and real-world problems of bioinformatics.  However, none of the
examples delves into arcane biotechologies, so Perl students with any
background or interests can attend and improve their skills.

The classes will be held from January 21-24 (Tue-Fri), 2003 at the
Amethyst Center in Davis Sq., Somerville, MA.

All the information about the classes and how to register can be found
at:

	http://stemsystems.com/class/

and it is mirrored at:

	http://kuiki.net/class/

So start off the New Year with the best Perl teacher anywhere around the
world (and Damian has been around it a few times!).  And a new training
budget comes with the New Year, so get your request in now before it
gets spent elsewhere.

We are again offering a 50% discount to the underemployed and students.

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

Date: 3 Jan 2003 15:41:18 -0800
From: bcross@xcalibr.org (Djinn)
Subject: date string to date format
Message-Id: <715f0b7.0301031541.6097e3df@posting.google.com>

I need to be able to take a date string and format it into a date
format so to be able to add, subtract from another date. How can i do
this?


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

Date: Fri, 03 Jan 2003 23:50:47 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: date string to date format
Message-Id: <3E16212E.2000108@rochester.rr.com>

Djinn wrote:

> I need to be able to take a date string and format it into a date
> format so to be able to add, subtract from another date. How can i do
> this?
> 

Check out the Date::Manip and Date::Calc modules.

-- 
Bob Walton



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

Date: Fri, 03 Jan 2003 20:57:22 -0600
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: date string to date format
Message-Id: <87u1gpoc4t.fsf@limey.hpcc.uh.edu>

>> On 3 Jan 2003 15:41:18 -0800,
>> bcross@xcalibr.org (Djinn) said:

> I need to be able to take a date string and format it
> into a date format so to be able to add, subtract from
> another date. How can i do this?

Date::Calc

and/or

Date::Manip

are the usual suspects here.  Get 'em through CPAN (or PPM
for ActiveState).

hth
t


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

Date: Fri, 3 Jan 2003 18:50:30 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Generating extra whitespace in for loop
Message-Id: <slrnb1cbum.sg2.tadmc@magna.augustmail.com>

LeshPhilling <lesh_philling@hotmail.com> wrote:

>         print "$result\n";


> and the extra
> lines after the numbers?


You should always enable warnings when developing Perl code.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 04 Jan 2003 01:41:52 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Generating extra whitespace in for loop
Message-Id: <3E163B5D.FD81DA4F@acm.org>

LeshPhilling wrote:
> 
> Hi
> 
> Here's the relevant code:
> 
> foreach $element (@output) {
>         ($result) = $element =~ m#list(.*?)files#;
>         print "$result\n";
> }
> 
> @output contains the following 5 lines (this is a snippet):
> 
> Command processed: Fri Jan  3 14:26:40 EST 2003 Received list 1432
> files
> debug output: print() processed
> Command processed: Fri Jan  3 13:55:32 EST 2003 Received list 38012
> files
> debug output: print() processed
> debug output: log file opened
> 
> I want to get the number of files (the value located between 'list'
> and 'files').  When I run this, I get this as a result:
> 
> [me@me:/] % ./test3.pl
>  1432
> 
>  38012
> 
> [me@me:/] %
> 
> Why the extra whitespace--both in front of both numbers and the extra
> lines after the numbers? Thanks!

Since you only want to capture digits change the regex to capture
digits:

foreach $element (@output) {
        ($result) = $element =~ m#list\D*(\d+)\D*files#;
        print "$result\n";
}



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 4 Jan 2003 01:09:51 +0100
From: "Murat Ünalan" <murat.uenalan@gmx.de>
Subject: Re: how to load a module depending on 'if' condition ?
Message-Id: <av58pf$fqq$01$1@news.t-online.com>

> Maybe Peter was not clear enough, but *this will not work*.
> The negating '!' binds stronger than 'eq', so the line above is
> equivalent to
>         if ( ( !$ENV{OSTYPE} ) eq 'linux' )

Right... i overlooked '!'

Murat




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

Date: Sat, 4 Jan 2003 00:05:36 +0100
From: "Marco.J.L." <luyendyk@yahoo.com.news>
Subject: Multipart error sendmail
Message-Id: <v1c5q145ari46b@corp.supernews.com>

Hello,

I want to use a multipart form with sendmail. When I use a form without
enctype="multipart/form-data"   the form works and I receive my testform by
email. But when I add the     enctype="multipart/form-data"      I don't get
any mail and i have an error 500 (internal server error)

I have to use multipart because I want in a later stadium to sent a form
with the possibility to use an attachment in the mail.

Thanx,

Marco J.L.




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

Date: 3 Jan 2003 15:56:55 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Multipart error sendmail
Message-Id: <3e162347@news.victoria.tc.ca>

Marco.J.L. (luyendyk@yahoo.com.news) wrote:
: Hello,

: I want to use a multipart form with sendmail. When I use a form without
: enctype="multipart/form-data"   the form works and I receive my testform by
: email. But when I add the     enctype="multipart/form-data"      I don't get
: any mail and i have an error 500 (internal server error)

: I have to use multipart because I want in a later stadium to sent a form
: with the possibility to use an attachment in the mail.

: Thanx,

: Marco J.L.

I will make a wild guess that this is related to perl because there is a
perl cgi script that is receiving the form data.

The problem seen above is most likely caused because the perl cgi script
does not know how to parse multipart/form-data. 

(If you are using matt's formmail script then perhaps you should get a
replacement for it.)

To usefully upload an attachment, the script will need to be able to parse
multipart/form-data.  The easiest way to enable that is for the script to
use the CGI.pm module.

However, even if the script can parse multipart/form-data, it will still
need to have additional code to access the uploaded data (because the data
is read from a file, not from a variable in memory), and will also need
additional code to build an email that includes the attachment (because
the data from the uploaded file cannot simply be pasted into a text mail
message). 

Because your script does not appear to understand "multipart/form-data", I
suspect it also lacks the code necessary to send an uploaded file as part
of the mail message, in which case you need to find another script, or
alter the script yourself.



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

Date: Sat, 04 Jan 2003 03:31:33 GMT
From: "Jodyman" <Jodyman@hotmail.com>
Subject: Re: Need help with split
Message-Id: <pAsR9.13512$9N5.1267692@newsread2.prod.itd.earthlink.net>


"John W. Krahn" <krahnj@acm.org> wrote in message
news:3E15154F.E518EBC7@acm.org...
> Jodyman wrote:
> >
> > TMTOW with Perl, You don't even need split, try this too:
> >
> > #!c:\perl\bin\perl -w
> > use strict;
> >
> > my $filename1 = 'c:\windows\system32\test.jpg';
> > my $filename2 = '/home/jodyman/pics/test.jpg';
> >
> > my ($results1) = $filename1 =~ /\\(\w+\.\w+)$/;
> > my ($results2) = $filename2 =~ /\/(\w+\.\w+)$/;
> > my ($results3) = $filename2 =~ /[\\|\/](\w+\.\w+)$/;
> > my ($results4) = $filename1 =~ /[\\|\/](\w+\.\w+)$/;
>                                      ^
> Which file system uses | to separate directory names?

Unix uses / Windows uses \   /[\\|\/](\w+\.\w+)$/;
                                                ^
Means look for either \ or /.

HTH,

Jody




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

Date: Sat, 04 Jan 2003 03:37:03 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Need help with split
Message-Id: <x74r8pziu9.fsf@mail.sysarch.com>

>>>>> "J" == Jodyman  <Jodyman@hotmail.com> writes:

  J> "John W. Krahn" <krahnj@acm.org> wrote in message
  J> news:3E15154F.E518EBC7@acm.org...
  >> Jodyman wrote:
  >> >
  >> > TMTOW with Perl, You don't even need split, try this too:
  >> >
  >> > #!c:\perl\bin\perl -w
  >> > use strict;
  >> >
  >> > my $filename1 = 'c:\windows\system32\test.jpg';
  >> > my $filename2 = '/home/jodyman/pics/test.jpg';
  >> >
  >> > my ($results1) = $filename1 =~ /\\(\w+\.\w+)$/;
  >> > my ($results2) = $filename2 =~ /\/(\w+\.\w+)$/;
  >> > my ($results3) = $filename2 =~ /[\\|\/](\w+\.\w+)$/;
  >> > my ($results4) = $filename1 =~ /[\\|\/](\w+\.\w+)$/;
  >> ^
  >> Which file system uses | to separate directory names?

  J> Unix uses / Windows uses \   /[\\|\/](\w+\.\w+)$/;
  J>                                                 ^
  J> Means look for either \ or /.

no it doesn't. | is a plain char in a char class. so john's comment was
correct in asking you where | is used in a file system path.

that would be better written as:

	m{[\\/](\w+\.\w+)$}

or better yet, use File::Basename as others have mentioned.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
----- Stem and Perl Development, Systems Architecture, Design and Coding ----
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org
Damian Conway Perl Classes - January 2003 -- http://www.stemsystems.com/class


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

Date: Sat, 04 Jan 2003 04:14:28 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Need help with split
Message-Id: <3E165F20.B0B3BBA4@acm.org>

Jodyman wrote:
> 
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3E15154F.E518EBC7@acm.org...
> > Jodyman wrote:
> > >
> > > TMTOW with Perl, You don't even need split, try this too:
> > >
> > > #!c:\perl\bin\perl -w
> > > use strict;
> > >
> > > my $filename1 = 'c:\windows\system32\test.jpg';
> > > my $filename2 = '/home/jodyman/pics/test.jpg';
> > >
> > > my ($results1) = $filename1 =~ /\\(\w+\.\w+)$/;
> > > my ($results2) = $filename2 =~ /\/(\w+\.\w+)$/;
> > > my ($results3) = $filename2 =~ /[\\|\/](\w+\.\w+)$/;
> > > my ($results4) = $filename1 =~ /[\\|\/](\w+\.\w+)$/;
> >                                      ^
> > Which file system uses | to separate directory names?
> 
> Unix uses / Windows uses \   /[\\|\/](\w+\.\w+)$/;
>                                                 ^
> Means look for either \ or /.
> 
> HTH,

Not really.

$ perl -we'
use strict;

my $filename1 = q[c:\windows\system32\test.jpg];
my $filename2 = q[/home/jodyman/pics/test.jpg];
my $filename3 = q[home|jodyman|pics|test.jpg];

my ($results1) = $filename1 =~ /[\\|\/](\w+\.\w+)$/;
my ($results2) = $filename2 =~ /[\\|\/](\w+\.\w+)$/;
my ($results3) = $filename3 =~ /[\\|\/](\w+\.\w+)$/;

print "$results1\n$results2\n$results3\n";
'
test.jpg
test.jpg
test.jpg


So again, which file system uses | to separate directory names?



John
-- 
use Perl;
program
fulfillment


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

Date: Sat, 4 Jan 2003 00:41:49 -0600
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Need help with split
Message-Id: <slrnb1d0hd.sue.tadmc@magna.augustmail.com>

Jodyman <Jodyman@hotmail.com> wrote:
> "John W. Krahn" <krahnj@acm.org> wrote in message
> news:3E15154F.E518EBC7@acm.org...
>> Jodyman wrote:

>> > my $filename1 = 'c:\windows\system32\test.jpg';

>> > my ($results4) = $filename1 =~ /[\\|\/](\w+\.\w+)$/;
>>                                      ^
>> Which file system uses | to separate directory names?
> 
> Unix uses / Windows uses \   /[\\|\/](\w+\.\w+)$/;


Windows can also use /.


> Means look for either \ or /.


Your character class can match any of _three_ characters.

Besides the two you list, it can also match |

| is not "meta" in a character class, it just matches |


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 03 Jan 2003 14:50:14 -0800
From: TruthXayer <truthxayer@yahoo.com>
Subject: Re: Newbie Reg. Exp. questions..
Message-Id: <3E1613A6.3090400@yahoo.com>

It might be overkill for ur application but the most correct way is to
use Net:IP module and ip_iptype or any of the other methods in there 
will return undef if its an invalid ip.


Joe Smith wrote:
> In article <aukr4g$qvd$1@nobel.pacific.net.sg>,
> -SmC- <invalid-email@melodyland.net> wrote:
> 
>>Can anyone teach me how to validate IP address?
>>have 4 group of 3 number and each group not over 255 ?
> 
> 
> There are valid IP addresses that do not match that definition.
>   127.1        is valid and equivalent to 127.0.0.1
>   127.16777215 is valid and equivalent to 127.255.255.255
>   128.0.65535  is valid and equivalent to 128.0.255.255
> 
> 	-Joe
> 



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

Date: Sat, 04 Jan 2003 01:35:21 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: Problem with huge dataset, 100000000 a magic number?
Message-Id: <3E1639D6.174A681F@acm.org>

Mike Hunter wrote:
> 
> Thanks for responding.  While I'm thinking of it, is there a way to get
> perl to tell you how much free memory remains on the machine?  Also, I
> read somewhere about perl auto-forking to get more memory, but I have
> subsequently been unable to find any info on that...does anybody know
> anything about that?
> 
> The code is gonna be a bit out of context without the surrounding
> flow-tools environment, but here's the segment you're interested in:
> 
> open DATA, "$flow_print_exe -l -f 5 < $tempdir/poi.$$ |" or
>      die "could not open flowprinted data pipe!";
> 
> print STDERR "Processing big data\n";
> 
> my %host_hash;
> 
> foreach my $host (@sorted_prelim)
> {
>         $existance_hash{$host} = 1;
> }
> 
> print "begginging while (<DATA)>)\n";
> 
> while (<DATA>)
> {
>         print "processing line $.\n" if (($. % 50000) == 0);
>         if (/^[^0-9]/)
>         {
>                 next;
>         }
>         my ($starttime, $endtime, $source_interface, $source_ip, $source_port,
>             $dest_interface, $dest_ip, $dest_port, $ip_prot, $tcp_flags,
>             $packets, $octets) = split /\s+/, $_;

If you are not using $starttime, $endtime, $source_interface, $dest_interface,
$ip_prot and $tcp_flags there is no reason to declare them.

         my ( undef, undef, undef, $source_ip, $source_port,
             undef, $dest_ip, $dest_port, undef, undef,
             $packets, $octets ) = split;

Or use a list slice:

         my ( $source_ip, $source_port,
              $dest_ip, $dest_port,
              $packets, $octets ) = (split)[3,4,6,7,10,11];


>         my @dest_split = split /\./, $dest_ip;
>         my @source_split = split /\./, $source_ip;
> 
>         my $dest_string = pack "CCCCS", $dest_split[0], $dest_split[1],
>            $dest_split[2], $dest_split[3], $dest_port;
> 
>         my $source_string = pack "CCCCS", $source_split[0], $source_split[1],
>            $source_split[2], $source_split[3], $source_port;

You will probably get better results if you use Socket::inet_aton to convert IP addresses.

use Socket;

 ...

         my $dest_string   = inet_aton( $dest_ip )   . pack 'S', $dest_port;
         my $source_string = inet_aton( $source_ip ) . pack 'S', $source_port;


John
-- 
use Perl;
program
fulfillment


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

Date: 03 Jan 2003 19:58:45 -0500
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: XS memory management
Message-Id: <m3adihenne.fsf@mumonkan.sunstarsys.com>

"Eric Anderson" <eric.anderson@cordata.net> writes:

[...]

> char * axBuildURI(pool *p, const char *URI, const char *base)
> {
>     return ap_pstrdup(p, (char *)xmlBuildURI(URI, base));
> }

[...]

Apache uses pools for memory management; you free memory ONLY
by clearing/destroying the pool that allocated it.  In the case
of apache, the person that creates a pool is usually responsible
for registering a cleanup handler with apache, which tells apache
to destroy the pool at the appropriate time.

> The purpose of the function seem so to be to build a URI when given a
> base path and a relative URI. For the most part is is simply wrapping
> the function xmlBuildURI from the libxml2 library. I looked up the
> function in that library and it says that it is the callers job to
> free the memory pointed to by the pointer returned.

The problem is that axBuildURI() doesn't hand you the result of
xmlBuildURI; it just hands you a pool-allocated copy.  That means
the axBuildURI function is responsible for free()ing the result of
xmlBuildURI.  You might try writing it like this instead:

  char *axBuildURI(...) 
  {
 
      char *tmp = (char *)xmlBuildURI(URI, base);
      char *rv;

      if (tmp == NULL)
          return NULL;

      rv = ap_pstrdup(p,tmp);
      free(tmp);
      return rv;
  }

> But as you can see from the code it simply does a strdup (a special
> Apache version). From what I can tell there is no way that the string
> returned from xmlBuildURI is ever freed since it is simply copied and
> never referenced again.

Right.  *If* xmlBuildURI malloc()s a string for its return value, 
the caller is responsible for free()ing it.   According to the 
docs for xmlBuildURI(), the axBuildURI() code leaks.

-- 
Joe Schaefer     "A man cannot be too careful in the choice of his enemies."
                                               --Oscar Wilde



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

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


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