Re: $^T inconsistant?

2004-07-14 Thread Robin
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thursday 15 July 2004 07:08, Randal L. Schwartz wrote:
> Yes.  Don't use prototypes.
Why not? And is there another way to ensure things like lists are passed as 
references?

- -- 
Robin <[EMAIL PROTECTED]> JabberID: <[EMAIL PROTECTED]>

Hostes alienigeni me abduxerunt. Qui annus est?

PGP Key 0x776DB663 = DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFA9dtLzTjgendttmMRAhX5AJ4jgqn8RCSqYsrK5Lg0nOLDYdAwzgCeJIbT
0/aLLLWKvvuDLzc2Wl63Onk=
=WIBV
-END PGP SIGNATURE-

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Need to write a pop3 attachment fetch program

2004-07-14 Thread Morbus Iff
>What I need is to write an application that:
>- Access a pop3 remote account
>- Iterate through the list of messages on the server
>- Download the attachments and save them localy on the machine
>- delete all downloaded messages

See http://disobey.com/detergent/code/leecharoo/leechpop.pl
The code was further explained in my book 'Spidering Hacks'.

-- 
Morbus Iff ( and think about the bad things that I didn't do )
Technical: http://www.oreillynet.com/pub/au/779
Culture: http://www.disobey.com/ and http://www.gamegrene.com/
icq: 2927491 / aim: akaMorbus / yahoo: morbus_iff / jabber.org: morbus

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Need to write a pop3 attachment fetch program

2004-07-14 Thread C.F. Scheidecker Antunes
Hello all,
Although I have done this same thing in PHP and Java before I have an 
urgent need to accomplish it in Perl due to specific requirements.

What I need is to write an application that:
- Access a pop3 remote account
- Iterate through the list of messages on the server
- Download the attachments and save them localy on the machine
- delete all downloaded messages
requirements:
- only attachments ending with .txt and .zip should be saved, the rest 
must be ignored.

OK, so I need help and directions on this.
What are the Perl CPAN modules to achieve it? Browsing CPAN I found: 
Net-POP3_auth-0.03.tar.gz and Mail-POP3Client-2.16.tar.gz.

However I do not know how can I handle the mime attachment requirement. 
Read the MIME body, save the attachment with its original name and only  
.txt and .zip files.

After that, I will need to unzip all the .zip files saved to check 
inside and do some processing.

I appreacite any help, any links to articles that teach how to do it in 
perl.

Thanks in advance,
C.F.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



search text

2004-07-14 Thread manojkumar vajram
Plz. help me . I am new to perl
I want to accept a pattern from screen
and search the pattern in my one or two text data base
and print the details

The pattern from screen may consist spaces and special
char. line / - etc.
I use redhat linux 8.0
I have coded like below but fetched no result
code-->
system( "echo -en 'Enter Pattern :\c'");
$pat = ;
open (FILEONE,"file1");
while(){
if($pat=~$_){print $_;}
close(FILEONE);
open (FILETWO,"file2");
while(){
if($pat=~$_){print $_;)
close(FILETWO);

end of code--->
plz. help me
thanks in advance
manojvajram



__
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
http://promotions.yahoo.com/new_mail

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Breaking up a large text stirng

2004-07-14 Thread Jeff 'japhy' Pinyan
On Jul 15, David Clarke said:

>Hi, I have a string of text that is thousands of characters in length.
>And I want to break it up into smaller records of say 500 or 600
>characters. Is there a Perl command to help to do this or am I stuck with
>looping through the large input record and counting field positions
>myself.

You can substr() or unpack() on the string to get the chunks.  I think
unpack() is the easiest, really.

  # this code was run with perl v5.8.4
  my @chunks = unpack "(a5)*", "hello, my name is japhy";
  print "<$_>\n" for @chunks;

The output:

  
  <, my >
  
  
  

-- 
Jeff "japhy" Pinyan %  How can we ever be the sold short or
RPI Acacia Brother #734 %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %-- Meister Eckhart


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Breaking up a large text stirng

2004-07-14 Thread Wagner, David --- Senior Programmer Analyst --- WGO
David Clarke wrote:
> Hi, I have a string of text that is thousands of characters in
> length. And I want to break it up into smaller records of say 500 or
> 600 characters. Is there a Perl command to help to do this or am I
> stuck with looping through the large input record and counting field
> positions myself.
> 
> Thanks all. Dav.
>  
> 
Do you want just chunks of 500 or 600 bytes, or breaks at particular points 
along the way?  If just junks, then you could use length, substr to get at the chunks. 
 If a particular character or character string, then you could use a regex and parens 
to grab and process what you want.

  Any questions and/or problems, please let me know.

  Thanks.

Wags ;)
Int: 9-8-002-2224
Ext: 408-323-4225x2224



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Breaking up a large text stirng

2004-07-14 Thread David Clarke
Hi, I have a string of text that is thousands of characters in length. And I want to 
break it up into smaller records of say 500 or 600 characters. Is there a Perl command 
to help to do this or am I stuck with looping through the large input record and 
counting field positions myself.
 
Thanks all. Dav.


***
This e-mail, including any attachments to it, may contain confidential and/or personal 
information.
If you have received this e-mail in error, you must not copy, distribute, or disclose 
it, use or take any action 
based on the information contained within it.

Please notify the sender immediately by return e-mail of the error and then delete the 
original e-mail.

The information contained within this e-mail may be solely the opinion of the sender 
and may not necessarily 
reflect the position, beliefs or opinions of Salmat on any issue.

This email has been swept for the presence of computer viruses known to Salmat's 
anti-virus systems.

For more information, visit our website at  www.salmat.com.au.
***



RE: $^T inconsistant?

2004-07-14 Thread Jenda Krynicky
From:   "perl.org" <[EMAIL PROTECTED]>
> On Wed, 14 Jul 2004 22:49:42 +0200, Jenda Krynicky wrote
> > 
> > And does the language-that-should-not-be-named support this?
> > 
> > ($x, $y) = some_function( $some, $params);
> 
> Sure, a method can return an array (or a Hash, depending on your
> object types).  It's just generally considered bad programming
> practice, like storing multiple values in a single database column.

I did not ask whether it supports the equivalent of

@ary = some_function( $some, $params);
$x = $ary[0];
$y = $ary[1];

And yeah I understand it's bad practice. It confuses the old C 
programmers used to call "function" something that doesn't return 
anything, but changes an array whose address the "function" got as a 
parameter. Bleargh.

Jenda

= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Calling Expect Script From a Perl Program

2004-07-14 Thread Ravinder Arepally
 
Calling Expect Script From a Perl Program, the perl program works fine
when executed in foreground (i.e on command line) but its does not
working in back ground (i.e schedule in a cron)..but if I call the same
expect script from a shell program it works both in back ground and
foreground. Your help is appreciated


Remote_ftp.exp 
#!/usr/local/bin/expect -f 
set force_conservative 0  ;# set to 1 to force conservative mode even if

  ;# script wasn't run conservatively originally

if {$force_conservative} { 
set send_slow {1 .1} 
proc send {ignore arg} { 
sleep .1 
exp_send -s -- $arg 
} 
} 
set timeout -1 
set rem_host [lindex $argv 0] 
set rem_user [lindex $argv 1] 
set rem_pswd [lindex $argv 2] 
set lcal_file [lindex $argv 3] 
set rem_file [lindex $argv 4] 
spawn $env(SHELL) 
match_max 10 
expect  "> " 
send -- "ftp $rem_host\r" 
expect  "Name *: " 
send -- "$rem_user\r" 
expect "Password: " 
send -- "$rem_pswd\r" 
expect  "ftp> " 
send -- "bin\r" 
expect "ftp> " 
send -- "send $lcal_file $rem_file\r" 
expect "ftp> " 
send -- "bye\r" 
expect "> " 
send -- "exit\r" 
expect eof 

Remote_ftp.pl 
#!/usr/local/bin/perl 
localFILE='/tmp/test99'; 
remFILE='/tmp/test99'; 
$command="/export/home/scripts/remote_ftp.exp server1 user1 mypwd
$localFILE $remFILE"; 
$output = `$command`; 
print $output 

Remote_ftp.sh 
#!/usr/bin/ksh 
/export/home/perl/remote_ftp.pl 



Uploading problems

2004-07-14 Thread Mike Blezien
Hello,
got a script that uploads images, and have used the same coding before with no 
problems, worked like a charm.

But for some reason, when I use this coding now, it produces a '0' bytes size 
image, the image is upload OK, in the proper folder, the correct image name is 
created, but it's zero bytes in file size.

Below is the sub routine that uploads the images. Everything goes through fine, 
no errors at all. Is there something on the server that maybe causing this, they 
got plenty of disc space on the machine. Uploads are not disabled in the 
CGI.pm... I'm lost as to what I've missed. Any help would be much appreciated.

##
# Upload file routine
sub ImageUpload {
my($subfolder,$binary_image) = @_;
unless(length($binary_image)>2) {
Error("The was a problem encounter while uploading banner imageBanner Image: 
$binary_image");
}
my @ext   = split(/\,/,$conf->{allowimages});
my $match = 0;
my $limit = $conf->{maxkbimage};

my($bytesread,$buffer,$image_name,$filesize,$newImage_file);
$image_name   = $binary_image;
$image_name   =~ s!^.*(\\|\/)!!;
chomp $image_name;
$newImage_file = $subfolder . $image_name;
for my $ext (@ext)
  {
  if (grep /$ext$/i,$image_name) { $match = 1; last; }
  }
	
   unless($match)
 {
  Error("Your upload file does not appear to be in the allowed image 
format!.");
	 }

open (OUTFILE,">$newImage_file") or Error("Could not open folder: 
$newImage_file. Reason: $!");

   binmode OUTFILE;
   while ($bytesread = read($binary_image, $buffer, 1024)) {
   print OUTFILE $buffer or Error("Could not save file. Reason: $!");
   }
   close (OUTFILE);
   chmod 0666, $newImage_file;
   $filesize = sprintf "%0.2f",(-s $newImage_file) / 1024;
   if ($filesize > $limit)
  {
unlink $newImage_file;
Error("FileSize: $filesizeYour Image exceeds the filesize limit of 
$limit KB's allowed");
  }

   if (!-B $newImage_file)
  {
unlink $newImage_file;
Error("Your Image does not appear to be in a valid binary format");
  }
# INSERTED print out here to verify the correct data is being passed and its
# fine
   print $cgi->header();
   print qq~Upload Image: $binary_image~; # OK
   print qq~Image File: $newImage_file~;  # OK
   print qq~Process Completed~;
   exit();
}
--
MikeBlezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://thunder-rain.com
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 22:49:42 +0200, Jenda Krynicky wrote
> 
> And does the language-that-should-not-be-named support this?
> 
>   ($x, $y) = some_function( $some, $params);

Sure, a method can return an array (or a Hash, depending on your object
types).  It's just generally considered bad programming practice, like storing
multiple values in a single database column.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 15:53:45 -0500, James Edward Gray II wrote
> On Jul 14, 2004, at 3:39 PM, perl.org wrote:
> 
> That was my Nice Voice, actually.  Ask the list.  I ran off some guy 
> using my Mean Voice recently.

No problem, I tend to upset a lot of people in a lot of forums.  People seem a
little over-invested in their knowledge sometimes, and
resultantly/inappropriately resistant to change/progress (though Perl 6 scares
me too).  There should be some kind of tone flag in email clients.  I'm a
joker, just keep that in mind.

> My main reason is that Perl's Method Dispatch bypasses them 
> altogether.   That makes them useless with objects and thus useless 
> to me most of the time.

I agree but I think that's a problem with the Perl engine, not with my use of it.

All the best,

   -John

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Data File getting set to an empty file

2004-07-14 Thread Jenda Krynicky
From: "Nigel Peck" <[EMAIL PROTECTED]>
> I have a (possible) problem with a script that records the number of
> page views for various pages on a site (full script below).
> 
> Every so often (60 days or more) the data file (data.xml) loses all
> it's data and is still there but empty.

Waitasecond ... all your CGI scripts try to edit a potentially huge 
XML file? I must be missing something here!

XML might be a fine format for exchanging information, but as an 
editable database it's almost the worst thing you could get.

No matter how good is the XML parser it takes ages to find the 
information and even longer to change the XML.

You should be using a database for this.

If you do not want to install any "real" one try DBD::SQLite. You'll 
find out the modifications are much much quicker.

Jenda
P.S.: Guess what happens if two instances of your script are started 
at the same time, both read the same XML, both make some changes and 
both write their changes to the file? Yes the write is "atomic", but 
there is nothing in the script preventing one instance from reading 
the XML between the other reads it and writes it!

 
> Any suggestions greatly appreciated.
> 
> Cheers,
> Nigel
> 
> -=-=-=-=-=Script Follows=-=-=-=-=-
> 
> use strict;
> use XML::LibXML;
> use CGI;
> use IO::AtomicFile;
> 
> sub build_dom (\$\$\$);
> sub commit_changes ($$\$);
> sub error ($);
> 
> my $query = new CGI;
> $CGI::DISABLE_UPLOADS = 1;
> 
> print "Content-type: text/html\n\n";
> 
> my $lasterror;
> my $data_file = "/home/sebs/pageviews/data.xml";
> my $error_file = "/home/sebs/pageviews/errors.txt";
> 
> my $location = $query->param("location") ||
>  error ('Required variable location was not sent');
> 
> my $data;
> 
> build_dom($data, $data_file, $lasterror)
>  || error($lasterror);
> 
> my $views;
> my $node = (($data->findnodes('//[EMAIL PROTECTED]"' . $location .
> '"]'))?($data->findnodes('//[EMAIL PROTECTED]"' . $location .
> '"]')->[0]):'');
> 
> if ( not $node ) {
> # It's a new page, not seen before, create a page element for it
>  $node = XML::LibXML::Element->new('page');
>  $node->setAttribute('location', $location);
>  $node->setAttribute('views', 0);
>  $node->setAttribute('starttime', time);
>  $data->getDocumentElement->appendChild($node);
> }
> 
> my $views = $node->getAttribute('views');
> 
> if ( $query->param("average") == 1 ) {
> # Send the average and die if average was set
>  my $starttime = $node->getAttribute('starttime');
>  my $timediff = time - $starttime;
>  # Seconds in a 30 day month
>  # 2592000
>  my $months = int($timediff / 2592000) + 1;
>  my $average = $views / $months;
>  print int($average);
>  die;
> }
> 
> unless ($query->param("noview") == 1) {
> # Increase views unless noview was set
>  $views++;
>  $node->setAttribute('views', $views);
> 
>  commit_changes($data, $data_file, $lasterror)
>   || error($lasterror);
> }
> 
> print $views;
> 
> ##
> #  COMMON SUBS   #
> ##
> 
> sub error ($) {
>  my ($errormsg) = @_;
>  print "Error\n";
>  print "Please note the information below, this was the cause of
>  the
> error.\n";
>  print "" . $errormsg . "\n";
>  open ( ERRORS, ">>$error_file" );
>  print ERRORS $errormsg . "\n";
>  close ( ERRORS );
>  die;
> }
> 
> ##
> #   DOM STUFF#
> ##
> 
> sub build_dom (\$\$\$) {
>  my ($doc, $config, $errormsg) = @_;
> 
>  my $parser = XML::LibXML->new();
>  $parser->validation(0);
>  $parser->expand_entities(1);
>  $parser->keep_blanks(0);
>  $parser->pedantic_parser(0);
>  $parser->load_ext_dtd(0);
>  $parser->complete_attributes(1);
> 
>  eval { $$doc = $parser->parse_file( $$config ) };
>  if ($@) { $$errormsg = "build_dom error: " . $@ . "\n"; return 0; }
>  else { return 1; }
> }
> 
> sub commit_changes ($$\$) {
>  my ($doc, $file, $errormsg) = @_;
>  my $fh;
>  unless ($fh = IO::AtomicFile->open($file,"w"))   { $$errormsg =
>  "Couldn't
> open filehandle to $file : $!";
>  return 0; }
> 
>  eval { $doc->toFH($fh, 1) };
>  if ($@) { $fh->delete();
> $$errormsg = "commit_changes error with $file : " . $@ . "\n";
> return 0;
>  } elsif ( not $fh->close() ) { $$errormsg = "Couldn't write file
>  $file"; } else { return 1 }
> }
> 
> -=-=-=-=-=Script Ends=-=-=-=-=-
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 


= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread James Edward Gray II
On Jul 14, 2004, at 3:39 PM, perl.org wrote:
On Wed, 14 Jul 2004 15:31:00 -0500, James Edward Gray II wrote
We're trying to teach you Perl.  Please remember that.  It's why you
are here.
This sure can be an unfriendly list...
That was my Nice Voice, actually.  Ask the list.  I ran off some guy 
using my Mean Voice recently.

Most of us Perl users aren't big on prototyping.  As far as I'm
concerned, it creates more issues than it solves.
This is what I'm trying to understand - what issues does it create?  I 
still
don't have a real answer.
Bob has already given you one.  It can spontaneously change the 
behavior of subs.

My main reason is that Perl's Method Dispatch bypasses them altogether. 
 That makes them useless with objects and thus useless to me most of 
the time.

Welcome to Perl.
I've been programming Perl for about 10 years.  I do hate the syntax 
and other
annoyances when I return to Perl from Java or C#, but I also 
appreciate the
flexibility.
Whatever you think is fine, but remember we like Perl.  ;)  Be good.
I hope to use this list as a forum for what I hope are best
practices and to further my understanding.  If I am not welcome here, 
just let
me know.
We are here to help you learn Perl.  We welcome your interest as long 
as you continue to welcome our Perl Way answers, agree or disagree...

James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: $^T inconsistant?

2004-07-14 Thread Jenda Krynicky
From: "perl.org" <[EMAIL PROTECTED]>
> On Wed, 14 Jul 2004 13:06:24 -0600, Wiggins d Anconia wrote
> > Typed return value, yikes, you have just cut out half of the value
> > of using a 4GL... Back to C with you! ;-)  Let's see if we can get
> > P5P to implement pointer arithmetic for references...uh
> 
> No, Java has this and no pointer arithmetic is required.

Do not speak the name of Satan!

And does the language-that-should-not-be-named support this?

($x, $y) = some_function( $some, $params);

or do I still have to jump through the hoops just to get two numbers 
out of a function like I did in C 30 (or is it 40?) years ago?

OTOH, not all static typed languages are bad. Some have a type system 
that's conceptualy newer than the state of the art 30 years ago. 
Shame both Java and C# are firmly rooted in the 70's.

Jenda
= [EMAIL PROTECTED] === http://Jenda.Krynicky.cz =
When it comes to wine, women and song, wizards are allowed 
to get drunk and croon as much as they like.
-- Terry Pratchett in Sourcery


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 15:31:00 -0500, James Edward Gray II wrote
> 
> We're trying to teach you Perl.  Please remember that.  It's why you 
> are here.

This sure can be an unfriendly list...

> Most of us Perl users aren't big on prototyping.  As far as I'm 
> concerned, it creates more issues than it solves.

This is what I'm trying to understand - what issues does it create?  I still
don't have a real answer.  In fact, in one response on why *not* to use
prototypes, the content included "it's probably best to prototype new functions".

> Welcome to Perl.

I've been programming Perl for about 10 years.  I do hate the syntax and other
annoyances when I return to Perl from Java or C#, but I also appreciate the
flexibility.  I hope to use this list as a forum for what I hope are best
practices and to further my understanding.  If I am not welcome here, just let
me know.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Help a newbie to fix a TK GUI script with toolbar children.

2004-07-14 Thread Marco Perl

Hi Team , I am always grateful for your help.

in a TK-GUI how to show grand-children of a child from toolbar.

I developed a TK-module for ActivePerl in Win-2000 env.

this script has a toolbar with 5 toolbar-items.

one of these items called "Tests" has a child called "Child...>" 

who has grand-children [choice1, choice2, choice3].

I want to click on "Child...>" and diplay grand-children to its right. i.e.

 

Tests

-

XYZ

ABC

Child...> choice1

   choice2

   choice3

what is the syntax to display [choice1, choice2, choice3] to the right of "Child...>"?

thanks a lot,
Marco.


-
Do you Yahoo!?
Read only the mail you want - Yahoo! Mail SpamGuard.

Re: $^T inconsistant?

2004-07-14 Thread James Edward Gray II
On Jul 14, 2004, at 3:18 PM, perl.org wrote:
OK, unless I'm missing something, I will only prototype my functions, 
not the
legacy code here.
We're trying to teach you Perl.  Please remember that.  It's why you 
are here.

Most of us Perl users aren't big on prototyping.  As far as I'm 
concerned, it creates more issues than it solves.

You may feel differently.  Fine.  It's in the language.  Use away.
However, the prototyping that's built into Perl really has little to do 
with named parameters.  I'm coming into this conversation late, so I 
didn't see what your problem is there.  We typically use paired 
hash-like parameters for this in Perl land.  It's a good fit, we think. 
 Flexible but powerful.

If you need to validate your parameters to some criteria, please do so. 
 If you find that too much work and only want to do it once, create a 
subroutine that does it for you.  Move that subroutine into a module 
and you can use it everywhere.  Throw it on the CPAN so we can too.

Welcome to Perl.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 15:55:35 -0400, Bob Showalter wrote
>
>It's probably best to prototype new functions, not retrofit
> prototyping
>into older ones.  

OK, unless I'm missing something, I will only prototype my functions, not the
legacy code here.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: $^T inconsistant?

2004-07-14 Thread Wiggins d Anconia
> On Wed, 14 Jul 2004 15:33:21 -0400, Bob Showalter wrote
> > 
> > Except that those are different in much more that just "documentation".
> > Don't go that way...
> 
> I still don't understand the reasoning for this - how could adding
more to the
> sub signature be worse than not having any?  Is there a URL that
describes why
> prototypes are bad?  and if they're bad, why are they in the
implementation at
> all, why don't they generate warnings and why are they not documented
to be
> deprecated?
> 

perldoc perlsub contains the documentation for prototypes.  To me they
are inflexible and involve too much work when changing the args, maybe I
am naive, but that is probably my lack of background in C/Java.  The
return value typing issue is much bigger for me, the beauty of Perl is
its contexts, and varying return value types at runtime.  Late typing? 
Can't remember what it is called

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: $^T inconsistant?

2004-07-14 Thread Bob Showalter
perl.org wrote:
> On Wed, 14 Jul 2004 15:45:52 -0400, Bob Showalter wrote
> > perl.org wrote:
> > > 
> > > I still don't understand the reasoning for this - how could adding
> > > more to the sub signature be worse than not having any?
> > 
> > This is explained in perldoc perlsub.
> 
> What section are you referring to? 

This section:

   It's probably best to prototype new functions, not retrofit
prototyping
   into older ones.  That's because you must be especially careful about
   silent impositions of differing list versus scalar contexts.  For
exam-
   ple, if you decide that a function should take just one parameter,
like
   this:

   sub func ($) {
   my $n = shift;
   print "you gave me $n\n";
   }

   and someone has been calling it with an array or expression returning
a
   list:

   func(@foo);
   func( split /:/ );

   Then you've just supplied an automatic "scalar" in front of their
argu-
   ment, which can be more than a bit surprising.  The old "@foo" which
   used to hold one thing doesn't get passed in.  Instead, "func()" now
   gets passed in a "1"; that is, the number of elements in "@foo".  And
   the "split" gets called in scalar context so it starts scribbling on
   your "@_" parameter list.  Ouch!

Follow Randal's advice if you don't like mine :~)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread James Edward Gray II
On Jul 14, 2004, at 2:50 PM, perl.org wrote:
This does kindof make me laugh though:
"Alphanumerics have
been intentionally left out of prototypes for the express purpose of
someday in the future adding named, formal parameters"
Sorry in advance to anyone who will inform me that's copyrighted 
content.
I believe named parameters are coming in Perl 6.
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 15:45:52 -0400, Bob Showalter wrote
> perl.org wrote:
> > 
> > I still don't understand the reasoning for this - how could adding
> > more to the sub signature be worse than not having any?
> 
> This is explained in perldoc perlsub.

What section are you referring to?  The version I have has section on
prototypes but nothing seems to indicate that they shouldn't be used (is there
something specific I should grep for?).

This does kindof make me laugh though:

"Alphanumerics have
been intentionally left out of prototypes for the express purpose of
someday in the future adding named, formal parameters"

Sorry in advance to anyone who will inform me that's copyrighted content.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: $^T inconsistant?

2004-07-14 Thread Bob Showalter
perl.org wrote:
> On Wed, 14 Jul 2004 15:33:21 -0400, Bob Showalter wrote
> > 
> > Except that those are different in much more that just
> > "documentation". Don't go that way...
> 
> I still don't understand the reasoning for this - how could adding
> more to the sub signature be worse than not having any?

This is explained in perldoc perlsub.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread James Edward Gray II
On Jul 14, 2004, at 2:27 PM, perl.org wrote:
I would like to use them if just for documentation purposes - it is 
just
slightly more clear to me to see

sub something( $$$ )
{
than
sub something
{
In Perl, we write that:
sub something {
my($param1, $param2, $etc) = @_;
# 
}
James
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 15:33:21 -0400, Bob Showalter wrote
> 
> Except that those are different in much more that just "documentation".
> Don't go that way...

I still don't understand the reasoning for this - how could adding more to the
sub signature be worse than not having any?  Is there a URL that describes why
prototypes are bad?  and if they're bad, why are they in the implementation at
all, why don't they generate warnings and why are they not documented to be
deprecated?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: $^T inconsistant?

2004-07-14 Thread Bob Showalter
perl.org wrote:
> I would like to use them if just for documentation purposes - it is
> just slightly more clear to me to see
> 
> sub something( $$$ )
> {
> 
> than
> 
> sub something
> {

Except that those are different in much more that just "documentation".
Don't go that way...

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 13:06:24 -0600, Wiggins d Anconia wrote
> 
> Yikes, funny I see this as a feature.  You were still passing the wrong
> value, your sub should validate the parameters itself, presuming
> thorough code, it would still have caused an error. 

No comprende.

> Typed return value, yikes, you have just cut out half of the value of
> using a 4GL... Back to C with you! ;-)  Let's see if we can get P5P 
> to implement pointer arithmetic for references...uh

No, Java has this and no pointer arithmetic is required.

> As Bob stated, I have never used them, though I don't consider 
> myself a true guru.

I would like to use them if just for documentation purposes - it is just
slightly more clear to me to see

sub something( $$$ )
{

than

sub something
{

Still nothing near what I would hope for in 2004, but at least a step.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Extracting headers of a Table in Perl.

2004-07-14 Thread Nicolay A. Vasiliev
Hello, Jason Corbett!
You need to learn about $sth->{'NAME'}. Use perldoc dbd::mysql.
I want to query a database and get data, but the headers don't come back. Is there a 
way that I can extract the headers of a table using Perl? Would it be easier to create 
a format, or should this be done in my SQL script? I don't have 'write' authority to 
the script. I just call it or read it and then run the script from where its at on the 
server.
Thanks,
JC
 


--
-
Nicolay A. Vasiliev
http://www.spamliquidator.com - Real spam fighter
http://www.soft411.com - Excellent soft archive

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Date module

2004-07-14 Thread Wiggins d Anconia
> Hi all,
> 
> I'm in search of a module that will give me the day of a week for a
> particular date.
> So for example, July 21 would return Wed
> 
> I checked CPAN but nothing jumped out at me.
> 

Nothing at all?

http://search.cpan.org/modlist/Data_and_Data_Types/Date
http://search.cpan.org/~stbey/Date-Calc-5.3/Calc.pod (Day_of_Week $dow =
Day_of_Week($year,$month,$day);)
http://search.cpan.org/~drolsky/DateTime-0.2101/lib/DateTime.pm
($dow= $dt->day_of_week;# 1-7 (Monday is 1) - also dow, wday)

Jumping might be a bit of a stretch, but some effort is needed.  I don't
think they have added the 'how high' switch to the CPAN search yet

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread Randal L. Schwartz
> "Perl" == Perl Org <[EMAIL PROTECTED]> writes:

Perl> I mistyped on my last post - I have seen suggestions that
Perl> prototypes should not even be used.  Is there a difinitive
Perl> answer on this?

Yes.  Don't use prototypes.

:-)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<[EMAIL PROTECTED]> 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!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: $^T inconsistant?

2004-07-14 Thread Wiggins d Anconia
> On Wed, 14 Jul 2004 13:26:36 -0400, Bob Showalter wrote
> > 
> > I second the "huh?"
> > 
> > How did prototyping relate to the trouble with $^T?
> > 
> > How do you define "support prototyping properly?"
> 
> Basically because of my implementation of named parameters.  I was passing
> -value instead of -seed and the sub was expecting -seed.  If I had
been using
> named parameters instead of hash keys this would not have been possible. 
>

Yikes, funny I see this as a feature.  You were still passing the wrong
value, your sub should validate the parameters itself, presuming
thorough code, it would still have caused an error. 
 
> By prototyping I really mean named and typed parameters and a typed return
> value (like C).

Typed return value, yikes, you have just cut out half of the value of
using a 4GL... Back to C with you! ;-)  Let's see if we can get P5P to
implement pointer arithmetic for references...uh

> 
> I mistyped on my last post - I have seen suggestions that prototypes
should
> not even be used.  Is there a difinitive answer on this?
> 
> 

As Bob stated, I have never used them, though I don't consider myself a
true guru.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Date module

2004-07-14 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Pam Derks wrote:
> Hi all,
> 
> I'm in search of a module that will give me the day of a week for a
> particular date.
> So for example, July 21 would return Wed
> 
> I checked CPAN but nothing jumped out at me.
> 
There are a number of modules, but for what you want, it would be just as easy 
to roll your own. You can use:

Time::Local

Then with 'localtime' and 'timelocal', you can come up with the day of week where Sun 
= 0 and Sat = 6. From this you would be able to setup for gettin Sun or Sat.

Wags ;)
 
> Any ideas?
> 
> Thanks in advance,
> Pam


***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help a newbie to pick best version of Linux for Perl and perl/TK.

2004-07-14 Thread Harald Richard Ashburner
Marco Perl said:
>
>Hi, Could you tell me what version of Linux is the most stable and 
>
>with most lib modules to do pearl and perl/TK?
>
Hi Marco,
Hmmm, how to start a flame war :)


I use debian myself, which has a reputation for stability. So what. They're all good. 
I reccomend using whatever distribution your friends are using or is popular at your 
friendly local linux users group.

knoppix http://www.knoppix.org boots of a cd so you can play with it
while you make up your mind if it's for you without messing around with
hard disk reformatting until you are sure.



As far as I am aware, all current distributions come with Perl 5.8+ as
standard, cpan does the rest for you, including TK.


-- 
Kind regards,
Hal Ashburner

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Date module

2004-07-14 Thread Pam Derks
Hi all,

I'm in search of a module that will give me the day of a week for a
particular date.
So for example, July 21 would return Wed

I checked CPAN but nothing jumped out at me.

Any ideas?

Thanks in advance,
Pam


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: Help a newbie to pick best version of Linux for Perl and perl /TK.

2004-07-14 Thread Bob Showalter
Marco Perl wrote:
> Hi, Could you tell me what version of Linux is the most stable and
> with most lib modules to do pearl and perl/TK?

http:/www.freebsd.org

I couldn't resist...  :~)

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Help a newbie to pick best version of Linux for Perl and perl/TK.

2004-07-14 Thread Andrew Gaffney
Marco Perl wrote:
Hi, Could you tell me what version of Linux is the most stable and 

with most lib modules to do pearl and perl/TK?
I really appreciate your experience.
Marco.
What exactly are you talking about? Almost all Linux distributions are "stable" 
and come with Perl. Usually, the version of the Linux kernel won't affect 
anything in Perl or Perl/Tk, either.

--
Andrew Gaffney
Network Administrator
Skyline Aeronautics, LLC.
636-357-1548
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: $^T inconsistant?

2004-07-14 Thread Bob Showalter
perl.org wrote:
> On Wed, 14 Jul 2004 13:26:36 -0400, Bob Showalter wrote
> > 
> > I second the "huh?"
> > 
> > How did prototyping relate to the trouble with $^T?
> > 
> > How do you define "support prototyping properly?"
> 
> Basically because of my implementation of named parameters.  I was
> passing -value instead of -seed and the sub was expecting -seed.  If
> I had been using named parameters instead of hash keys this would not
> have been possible. 

You might look at the CPAN module Params::Validate for this kind of thing.

> 
> By prototyping I really mean named and typed parameters and a typed
> return value (like C).

OK. "Prototyping" in perl has a specific (and different) meaning. It's
documented in perlsub.

Basically, it's used so you can write subs that act more like some of the
built-in subs.

Consider push():

   push(@array, 'foo', 'bar');

Without prototypes, you can't really write your own version of push(),
because the contents of @array get flattened along with the remaining args
into a single @_ list. Your own version would need to be called more like:

   my_push([EMAIL PROTECTED], 'foo', 'bar');

With perl's prototypes, you can tell the compiler to require an array name,
and yet pass a reference to that array as the actual parameter.

It really has nothing to do with named formal arguments or type checking in
the C-style prototypes sense.

> 
> I mistyped on my last post - I have seen suggestions that prototypes
> should not even be used.  Is there a difinitive answer on this?

I would agree with this. Prototypes are never needed AFAIK, and I have never
used them in any of the code I've written.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Help a newbie to pick best version of Linux for Perl and perl/TK.

2004-07-14 Thread Marco Perl

Hi, Could you tell me what version of Linux is the most stable and 

with most lib modules to do pearl and perl/TK?

I really appreciate your experience.
Marco.


-
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!

RE: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 13:26:36 -0400, Bob Showalter wrote
> 
> I second the "huh?"
> 
> How did prototyping relate to the trouble with $^T?
> 
> How do you define "support prototyping properly?"

Basically because of my implementation of named parameters.  I was passing
-value instead of -seed and the sub was expecting -seed.  If I had been using
named parameters instead of hash keys this would not have been possible. 

By prototyping I really mean named and typed parameters and a typed return
value (like C).

I mistyped on my last post - I have seen suggestions that prototypes should
not even be used.  Is there a difinitive answer on this?



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: $^T inconsistant?

2004-07-14 Thread Bob Showalter
perl.org wrote:
> We can all breath a sigh of relief now that I believe I've identified
> this as my bug.  I would say the true root cause is that Perl doesn't
> support prototyping properly and named parameters at all though...

I second the "huh?"

How did prototyping relate to the trouble with $^T?

How do you define "support prototyping properly?"

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread perl.org
On Wed, 14 Jul 2004 11:05:45 -0600, Wiggins d Anconia wrote
> > We can all breath a sigh of relief now that I believe I've identified
> this as
> > my bug.  I would say the true root cause is that Perl doesn't support
> > prototyping properly and named parameters at all though...
> > 
> 
> properly, huh?  and huh?
> 
> http://danconia.org

It would be nice to have a discussion on prototypes - from what I understand
they are not really enforced and I have even seen some suggestions on how to
change them.

As far as named parameters, I mean like most languages, something like:

sub whatever( param1, param2 )
{
  if ( param1 )

I get around this by calling whatever like

whatever( -param1 => value, -param2 => value )

then 

sub whatever
{
  my %{params} = normalizeParams( @{_} )

but this is obviously broken as the params aren't validated, resulting in my
original defect.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread Wiggins d Anconia
> We can all breath a sigh of relief now that I believe I've identified
this as
> my bug.  I would say the true root cause is that Perl doesn't support
> prototyping properly and named parameters at all though...
> 

properly, huh?  and huh?

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Getopt::Std vs. Getopt::Long

2004-07-14 Thread Wiggins d Anconia
> I have been using Getopt::Std for some time and I'm pretty happy with it. 
> I've been reading about Getopt::Long and it seems to support everything in
> Getopt::Std and has some nice conveniences.  Does anyone have experience
> converting scripts (or just development process) from Std to Long?  Does
> anyone have pretty good code examples using Getopt::Long?
> 

I created a template for use with Getopt::Long a while ago and posted it
here, then put it on my site, as well as a quick ref for G::L.

Both can be had here:

http://danconia.org/cgi-bin/request?handler=Content;content=StaticPage;label=perl

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: $^T inconsistant?

2004-07-14 Thread perl.org
We can all breath a sigh of relief now that I believe I've identified this as
my bug.  I would say the true root cause is that Perl doesn't support
prototyping properly and named parameters at all though...

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Getopt::Std vs. Getopt::Long

2004-07-14 Thread perl.org
I have been using Getopt::Std for some time and I'm pretty happy with it. 
I've been reading about Getopt::Long and it seems to support everything in
Getopt::Std and has some nice conveniences.  Does anyone have experience
converting scripts (or just development process) from Std to Long?  Does
anyone have pretty good code examples using Getopt::Long?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: Reading a variable file name

2004-07-14 Thread JupiterHost.Net
[EMAIL PROTECTED] wrote:
Lee,
Hello,
A couple of questions:
Ok, but please post to the list so everyone can share :)
1. I get an error on the use File::Slurp line.  I have been  looking in 
the "Camel" book and can't seem to find much.  Is this a module that I 
need to download.
Yes,
 perl -MCPAN -e 'install File::Slurp;'
shoudl do it
2. If I comment out the Slup line, my next error is on the read_dir 
line.  It thinks that this is a subroutine.
It is a subroutine, exported by File::Slurp; which you need to install
3. I would assume that the append_file line will have the same problem 
as the read_dir line, but I haven't gotten to it yet.
Correct same as #2
Many thanks for your help.
No problem! If you want to show your appreciation you could always 
signup for hosting at JupiterHost.Net and tell your friends - tell them 
Lee sent you :)

Richard Hug
HTH :)
Lee.M - JupiterHost.Net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Extracting headers of a Table in Perl.

2004-07-14 Thread jason corbett
I want to query a database and get data, but the headers don't come back. Is there a 
way that I can extract the headers of a table using Perl? Would it be easier to create 
a format, or should this be done in my SQL script? I don't have 'write' authority to 
the script. I just call it or read it and then run the script from where its at on the 
server.
 
Thanks,
JC


Re: perl POE

2004-07-14 Thread Wiggins d Anconia
> 
> Ricardo SIGNES wrote:
> 
> >* Anish Mehta <[EMAIL PROTECTED]> [2004-07-07T04:49:30]
> >  
> >
> >>Does anyone knows about some good links on PERL POE, how it allows
> >>
> >>
> >Perl
> >  
> >
> >>code to make asynchronous, non-blocking I/O calls and handle those I/O
> >>calls on the basis of Event Driven model and Event Queues.
> >>
> >>
> >
> >poe.perl.org
> >
> >or, of course, the current front page article on perl.com:
> > http://www.perl.com/pub/a/2004/07/02/poeintro.html
> >  
> >
> 
> >  
> >
> I have read from the above two links mentioned. Now Specifically what 
> should i read to know about "How to make asynchronous, non-blocking I/O 
> calls and handle those I/O calls on the basis of Event Driven model and 
> Event Queues..
> 

Do you understand what you are actually asking?  Do you understand what
asynchronous, non-blocking IO is?  Or what an event model is?  It seems
(not saying it is, just seems) that someone has thrown buzz words at you
and now you are asking about them, rather than having a real need.  If
so you need to understand these baseline items first.

POE is not something that can be picked up overnight, you need to
understand it fundamentally before you can do any specific tasks with
it.  You may want to start at:

perldoc perlipc

Then you need to read much more about POE Sessions, how it works as an
event model.  Then download and play with the examples in the POE
cookbook, run them, tweak them, run them again until you understand what
it really is doing.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Data File getting set to an empty file

2004-07-14 Thread Nigel Peck
Hi all,

I have a (possible) problem with a script that records the number of page
views for various pages on a site (full script below).

Every so often (60 days or more) the data file (data.xml) loses all it's
data and is still there but empty.

Any suggestions greatly appreciated.

Cheers,
Nigel

-=-=-=-=-=Script Follows=-=-=-=-=-

use strict;
use XML::LibXML;
use CGI;
use IO::AtomicFile;

sub build_dom (\$\$\$);
sub commit_changes ($$\$);
sub error ($);

my $query = new CGI;
$CGI::DISABLE_UPLOADS = 1;

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

my $lasterror;
my $data_file = "/home/sebs/pageviews/data.xml";
my $error_file = "/home/sebs/pageviews/errors.txt";

my $location = $query->param("location") ||
error ('Required variable location was not sent');

my $data;

build_dom($data, $data_file, $lasterror)
|| error($lasterror);

my $views;
my $node = (($data->findnodes('//[EMAIL PROTECTED]"' . $location .
'"]'))?($data->findnodes('//[EMAIL PROTECTED]"' . $location . '"]')->[0]):'');

if ( not $node ) {
# It's a new page, not seen before, create a page element for it
$node = XML::LibXML::Element->new('page');
$node->setAttribute('location', $location);
$node->setAttribute('views', 0);
$node->setAttribute('starttime', time);
$data->getDocumentElement->appendChild($node);
}

my $views = $node->getAttribute('views');

if ( $query->param("average") == 1 ) {
# Send the average and die if average was set
my $starttime = $node->getAttribute('starttime');
my $timediff = time - $starttime;
# Seconds in a 30 day month
# 2592000
my $months = int($timediff / 2592000) + 1;
my $average = $views / $months;
print int($average);
die;
}

unless ($query->param("noview") == 1) {
# Increase views unless noview was set
$views++;
$node->setAttribute('views', $views);

commit_changes($data, $data_file, $lasterror)
|| error($lasterror);
}

print $views;

##
#  COMMON SUBS   #
##

sub error ($) {
my ($errormsg) = @_;
print "Error\n";
print "Please note the information below, this was the cause of the
error.\n";
print "" . $errormsg . "\n";
open ( ERRORS, ">>$error_file" );
print ERRORS $errormsg . "\n";
close ( ERRORS );
die;
}

##
#   DOM STUFF#
##

sub build_dom (\$\$\$) {
my ($doc, $config, $errormsg) = @_;

my $parser = XML::LibXML->new();
$parser->validation(0);
$parser->expand_entities(1);
$parser->keep_blanks(0);
$parser->pedantic_parser(0);
$parser->load_ext_dtd(0);
$parser->complete_attributes(1);

eval { $$doc = $parser->parse_file( $$config ) };
if ($@) { $$errormsg = "build_dom error: " . $@ . "\n"; return 0; }
else { return 1; }
}

sub commit_changes ($$\$) {
my ($doc, $file, $errormsg) = @_;
my $fh;
unless ($fh = IO::AtomicFile->open($file,"w"))  { $$errormsg = "Couldn't
open filehandle to $file : $!";
  return 0; }

eval{ $doc->toFH($fh, 1) };
if ($@) { $fh->delete();
  $$errormsg = "commit_changes error with $file : " . $@ . "\n";
  return 0;
} elsif ( not $fh->close() ){ $$errormsg = "Couldn't write file $file";
} else { return 1 }
}

-=-=-=-=-=Script Ends=-=-=-=-=-


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: how to extract digit from a line in Perl

2004-07-14 Thread Bob Showalter
Franklin wrote:
> Hello:
> 
> I want to extract the digit from a line of text. For exmple, for a
> text line: TSC2101Net, how can I write a script to extract 2101 and
> print it?  

Use a regex to capture a series of digits:

  $_ = 'TSC2101Net';
  my ($num) = /(\d+)/;
  print "Found $num\n" if defined $num;

This will simply find the leftmost sequence of one or more digits in the
string.

HTH

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: 2 Socket questions

2004-07-14 Thread Bob Showalter
Kelvin Wu wrote:
> hello,
> 
> 
> 1, how to use http 1.1 via IO::Socket?

Create a tcp connection to the server using IO::Socket->new and send the
HTTP request. Read the response and handle it appropriately. Better yet, use
a higher-level module like LWP::Simple or LWP::UserAgent for this.

> 
> 2, if i have a script like this:
> &connectserver();
> &answerserver();
> &closeserver ();

Erm, don't write subroutine calls like that anymore. Lose the &'s.

> 
> how to do a parallel processing while waiting for server response?
> use fork? 

That's an easy way to manage it.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: how to extract digit from a line in Perl

2004-07-14 Thread iko
Franklin wrote:

> Hello:
> I want to extract the digit from a line of text. For exmple, for a
> text line: TSC2101Net, how can I write a script to extract 2101 and
> print it?
> Thank you very much in advance!
> Bestwishes
> Franklin
>
>   
>   
>
> 
>  /IncrediMail/
> - *Email has finally evolved* - *_Click Here_*
> 

try this [take your own risk :) ] :

**cut here*
#!/usr/bin/perl
#

$bannerkoe=<;

foreach $bingung(@fh) {
@pecah=split/ /,$bingung;
foreach (@pecah) {
@kar=split//,$_;
foreach $elemen(@kar) {
$hasil=$elemen=~m/(\d+)/;
if ($hasil) {print "$elemen";}
}
}
print "\nasalnya : $bingung\n";
}

close(FH);
cut here**

the content of tes_regex2.txt :
aku tes aja ya...
TSC2101Net
:)



Iko Riyadi
Departemen Data Manajemen
PT. Infomedia Nusantara
Jl. Kusuma Bangsa 10-12
Surabaya 60272 Indonesia
Telp: +62 (031) 5326282, Fax: +62 (031) 5343613
http://www.yellowpages.co.id

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: how to extract digit from a line in Perl

2004-07-14 Thread NYIMI Jose (BMB)
Title: Message



 

  
  -Original Message-From: Franklin 
  [mailto:[EMAIL PROTECTED] Sent: Wednesday, July 14, 2004 12:01 
  PMTo: [EMAIL PROTECTED]Subject: how to extract digit 
  from a line in Perl
  

  
Hello:
 
I want to extract the digit from a line of text. For exmple, for a 
text line: TSC2101Net, how can I write a script to extract 2101 and print it?
 
Thank you very much in advance!
 
Bestwishes
Franklin
 
 

  

  
  



    
  IncrediMail - Email has finally evolved - Click Here 
   
   
  If you are SURE that your digits are always between TSC and Net,
  You can do the following:
  my ($number)=$text=~/TSC(\d+)Net/;
  print "$number\n";
  HTH,
  José.

 DISCLAIMER 

"This e-mail and any attachment thereto may contain information which is confidential and/or protected by intellectual property rights and are intended for the sole use of the recipient(s) named above. 
Any use of the information contained herein (including, but not limited to, total or partial reproduction, communication or distribution in any form) by other persons than the designated recipient(s) is prohibited. 
If you have received this e-mail in error, please notify the sender either by telephone or by e-mail and delete the material from any computer".

Thank you for your cooperation.

For further information about Proximus mobile phone services please see our website at http://www.proximus.be or refer to any Proximus agent.




IMSTP.gif
Description: IMSTP.gif


Re: how to extract digit from a line in Perl

2004-07-14 Thread David Dorward
On 14 Jul 2004, at 11:00, Franklin wrote:
I want to extract the digit from a line of text. For exmple, for a 
text line: TSC2101Net, how can I write a script to extract 2101 and 
print it?
There are number of techniques that spring to mind, the obvious being 
regular expressions and substring. The latter isn't much good unless 
you know the position of the numbers in the string. The former is more 
flexible but also more complex.

perldoc perlrequick
perldoc -f substr
  IncrediMail - Email has finally evolved - Click Here
Evolved into a distracting blinking thing that gives me a headache. 
Eugh.

--
David Dorward
 

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



how to extract digit from a line in Perl

2004-07-14 Thread Franklin






Hello:
 
I want to extract the digit from a line of text. For exmple, for a text line: TSC2101Net, how can I write a script to extract 2101 and print it?
 
Thank you very much in advance!
 
Bestwishes
Franklin
 
 







  IncrediMail - Email has finally evolved - Click Here

Re: MIME coding & flags for sending a .csv or Excel file (Question)

2004-07-14 Thread John W . Krahn
On Tuesday 13 July 2004 07:20, jason corbett wrote:
>
> Thanks John. This was my first PERL program that I wrote and I wasn't
> sure when to use the my vs the our, but your points are well
> respected. I need more practice to understand how the
> functions/script work so that I can condense the programming better.

Perhaps Randal's article might help clarify it for you:
http://www.stonehenge.com/merlyn/UnixReview/col46.html

MJD's article may help as well:
http://perl.plover.com/FAQs/Namespaces.html

> Question: Is the scalar function always use to return values in a
> sub?

No.  A subroutine's return value is determined by the context in which 
it is called.  You can use the wantarray() function to determine the 
context from inside the subroutine.

perldoc -f wantarray

> Or is this a quick and easy way to do this without using the
> actual return statement?

In a subroutine, the last evaluated expression determines the value 
returned if the return keyword is not used.


John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]