Re: moving files

2004-09-30 Thread Sean Davis
HTTP header, I imagine.  There is a section in the CGI documentation 
about generating these headers.

Sean
On Sep 30, 2004, at 12:25 AM, Jeff Herbeck wrote:
So, what kind of header are we talking about here.  (I'm still 
learning)

Jeff
On Wed, 29 Sep 2004 12:43:46 -0600, Wiggins d Anconia
[EMAIL PROTECTED] wrote:
Make sure to group reply so that others can help and be helped (and to
avoid getting accidentally ignored)...please bottom post...
OK, here is what I have so far
use CGI;
use LWP::Simple;
$URL = http://www.jeffherbeck.com/arch.doc;;
$remote_user = $ENV{REMOTE_USER};
getstore($URL, /var/www/html/$remote_user);
and I keep getting
Server error!
The server encountered an internal error and was unable to complete
your request.
Error message:
Premature end of script headers: test.cgi
If you think this is a server error, please contact the webmaster.
Error 500

Could you lead me futher?
The above does not have a header printed, which is the most common
reason why you would get a 500 error.  Following that, unless you 
print
some response you will also get the Document Contains No Data error 
on
the client side. In general when you have a 500 error you triple check
that a proper header is being printed, that nothing is printed before
the header, and from there use the web server log to diagnose further
causes, such as syntax errors, etc. or use the fatalsToBrowser switch 
to
have errors go to the client (not necessarily advisable in production
facing systems).

Thanks
Jeff
http://danconia.org
snip
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Formmail help

2004-09-30 Thread William McKee
Hi Sander,

I'm not familiar with Exchange but if it speaks SMTP, you should be able
to use a module such as Mail::Sendmail or the newer Email::Send module
to talk to it. What formmail script are you using to process your forms?
I'd recommend the nms scripts[1].


HTH,
William

[1] http://nms-cgi.sourceforge.net/

-- 
Knowmad Services Inc.
http://www.knowmad.com

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




How to set default text on Tk::Text

2004-09-30 Thread Ramprasad A Padmanabhan
I am creating a TK widget with a TK::Text textbox. 

I want to set the default text value as hi like this 

$txt = $mw-Text(
 # -data =hi,  # This does not work 
 -width = '10', 
   -height = '10')-pack;


But this is not working. Any clues ? 

Thanks
Ram



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




OR in a regex

2004-09-30 Thread Colm Gallagher
Hi Folks,

Struggling to understand what is happening here...

Example of text is

Description Supports the management of the process to create and
complete an order Actors SYSTEM Pre-Conditions A Service Instance may
have been selected for the purchase

This regex extracts the text
/Description([^.]+)(?:Actors)/
Supports the management of the process to create and complete an order

In some cases, the word Actors that I want to terminate on is the
word Steps instead, so I though I'd use an OR inside parenthesis
with no backreferences ?: to match either Actors or Steps - this now
matches neither, so the pattern just runs to the end of the text

  (?!Change )Description([^.]+)(?:Actors|Steps)

any hints?

-- 
Colm

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: OR in a regex

2004-09-30 Thread Colm Gallagher
Oops, that example I gave actually works
It's always better to give the whole problem...

(?!Change )Description([^.]+)(?:Actors|Pre-Conditions|Post-Conditions)

What it's actually doing is matching the alternates but looking at the
string in reverse order.  I want to have look at the string in forward
order for the alternates, but still keep the reverse order in place
for the Description, but not Change Description bit

--
Colm

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




How Can I rename File using Perl?..

2004-09-30 Thread Roime bin Puniran
How can i rename any file using PERL?...Where should i start?..Where i can find any 
tutorial?

This e-mail and any attachments may contain confidential and
privileged information. If you are not the intended recipient,
please notify the sender immediately by return e-mail, delete this
e-mail and destroy any copies. Any dissemination or use of this
information by a person other than the intended recipient is
unauthorized and may be illegal.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: How Can I rename File using Perl?..

2004-09-30 Thread NYIMI Jose \(BMB\)


 -Original Message-
 From: Roime bin Puniran [mailto:[EMAIL PROTECTED] 
 Sent: Thursday, September 30, 2004 11:20 AM
 To: [EMAIL PROTECTED]
 Subject: How Can I rename File using Perl?..
 
 
 How can i rename any file using PERL?...Where should i 
 start?..Where i can find any tutorial?

C:\perldoc -f rename
rename OLDNAME,NEWNAME
Changes the name of a file; an existing file NEWNAME will be
clobbered. Returns true for success, false otherwise.

Behavior of this function varies wildly depending on your system
implementation. For example, it will usually not work across
file system boundaries, even though the system *mv* command
sometimes compensates for this. Other restrictions include
whether it works on directories, open files, or pre-existing
files. Check perlport and either the rename(2) manpage or
equivalent system documentation for details.


C:\

C:\perldoc perldoc

to learn how to use perldoc

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.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: OR in a regex

2004-09-30 Thread John W. Krahn
Colm Gallagher wrote:
Oops, that example I gave actually works
It's always better to give the whole problem...
(?!Change )Description([^.]+)(?:Actors|Pre-Conditions|Post-Conditions)
What it's actually doing is matching the alternates but looking at the
string in reverse order.  I want to have look at the string in forward
order for the alternates, but still keep the reverse order in place
for the Description, but not Change Description bit
It looks like your problem is that [^.]+ is greedy, it matches as many [^.] 
characters as possible and then backtracks until 
(?:Actors|Pre-Conditions|Post-Conditions) matches.  You need to use a 
non-greedy expression that won't backtrack.

(?!Change )Description([^.]+?)(?:Actors|Pre-Conditions|Post-Conditions)
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: How Can I rename File using Perl?..

2004-09-30 Thread Gavin Henry
Roime bin Puniran said:
 How can i rename any file using PERL?...Where should i start?..Where i
can find any tutorial?

using linux:

man mv

you can use a system() call or backticks ``


 This e-mail and any attachments may contain confidential and
 privileged information. If you are not the intended recipient,
 please notify the sender immediately by return e-mail, delete this
e-mail and destroy any copies. Any dissemination or use of this
 information by a person other than the intended recipient is
 unauthorized and may be illegal.

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response







-- 
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help with script

2004-09-30 Thread Jose Alves de Castro
On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote:
  I would like the output in the following format
  object1...tabDescription1
  object2...tabDescription2
  object3...tabDescription3
 
 
  perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME
  
  
  
  perl -l -00pe's/\n/\t/' FILENAME
 
 That's pretty slick you guys, he's sure to get an A+ ;)
 
 If your teacher requires the quotes to be removed:

What if the teacher requires an explanation? O:-)

It is my opinion that code should be explained, at least in this list.
 You're trying to teach people how to fish (and maybe swim). Giving them
 fish is good, of course, but tell them how you got it :-)

That said, nice code :-)

   perl -l -00pe's/\n/\t/;s/\//g;' FILENAME
 
 :)
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How Can I rename File using Perl?..

2004-09-30 Thread Jose Alves de Castro
On Thu, 2004-09-30 at 10:20, Roime bin Puniran wrote:
 How can i rename any file using PERL?...Where should i start?..Where i can find any 
 tutorial?

Try this

perldoc -f rename

HTH, :-)

jac

 This e-mail and any attachments may contain confidential and
 privileged information. If you are not the intended recipient,
 please notify the sender immediately by return e-mail, delete this
 e-mail and destroy any copies. Any dissemination or use of this
 information by a person other than the intended recipient is
 unauthorized and may be illegal.
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How Can I rename File using Perl?..

2004-09-30 Thread Chris Devers
On Thu, 30 Sep 2004, Gavin Henry wrote:

 Roime bin Puniran said:
  How can i rename any file using PERL?...Where should i start?..Where i
  can find any tutorial?
 
 using linux:
 
 man mv
 
 you can use a system() call or backticks ``

The question wasn't how to do this with Linux though, it was about how 
to use Perl. 

The message headers suggest that Roime is using Windows --

Content-Type: text/plain;  
   
charset=Windows-1252 
   

-- so the other response about the rename command was appropriate.

Moreover, rename() is a basic part of Perl, so even on Linux there is no 
need to do this with a system call to the `mv` command.



-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




GetOptions problems

2004-09-30 Thread cats



Hello Perl type people

 i am shore i had this working, but its all gone wrong for some resion the
options do not seem to be getting filled.

 can some one please help

the program is for searching through a large datafile (poller.cfg)
and outputting the found data in a more usefull format.

BTW i am not getting payed to dev this script it just make my job eayeser
and i get to try and lern perl too.
i guess this should all be structured better so if you have any
constructive comments =)

thank you.
RichT


/scanPoller.cfg.pl==
 more scanPoller.cfg.pl
#!/usr/local/bin/perl
#

use strict;
use warnings;
use Getopt::Long;

my
($inFile,$USAGE,$showKey,$site,$found,$foundKeys,@dataFile,@foundSegments,$value);
my ($opt_inFile, $opt_listAllFields, $opt_help ) = (0,0,0);
my $opt_findField = agentAddress;
my $opt_showFields = segment,agentAddress,community;

$USAGE = USAGETEXT;
usage: $0 ipaddress
  the following options are also availble
  [-inFile filename ] input filename
  [-findField fieldName ] this is the search key (default is
agentAddress)
  [-showFields field names ] feilds to output (default is
segment,agentAddress,community)
  [-listAllFields ] list avalible fields
  [-help] this help text
USAGETEXT

GetOptions(inFile=s,
findField=s,
showFields=s,
listAllFields,
help|h|H|?|HELP,
);

print  listAllFields =$opt_listAllFields\n;  #testing
print  help =$opt_help\n;  #testing


if ($opt_help == 1) {print $USAGE; exit; } # check to see if this is a
request for help, if so print USAGE
# start finding results
if ($opt_inFile != 0){  # find  results if we have in -inFile
open DFILE, $opt_inFile  # open $inFile and read in  or die
or die  could not open $opt_inFile;
@dataFile = DFILE;
close DFILE;

foreach $value (@dataFile) {  # loop  for each line/site in dataFile
chomp $value ;
@foundSegments=findVars($opt_findField,$value);
}
} elsif ($ARGV[0]) { # read in value from comandline

foreach $value ($ARGV[0]) {  # loop  for each line/site in dataFile
@foundSegments=findVars($opt_findField,$value);
}
} else {print $USAGE; exit; }

print  listAllFields =$opt_listAllFields\n;  #testing

# start printing results
if ($opt_listAllFields == 1) {
 for $found ( @foundSegments ) {
print \n ;
for $foundKeys (keys %$found) {
print $foundKeys,;
}
 }
} else {

 for $found ( @foundSegments ) {
foreach $showKey (split /,/, $opt_showFields) {
print $found-{$showKey},;
}
print \n;
 }
}

sub findVars {

# Function Check Discover Results
# Parameters :
#
# Returns :
#
#



my($findKey, $findValue, $segmentFieldKey, $segmentFieldValue,
%segmentFields, $nullVar, @foundSegments);

# read in Search Key and Value  from parent NOTE make a check for this
$findKey=$_[0] || die Missing Args $findKey $! ;
$findValue=$_[1] || die Missing Args $findValue $! ;
chomp $findValue;
chomp $findKey;
#my $NH_HOME= $ENV[NH_HOME];  # point to the poller CFG file
my $NH_HOME= .;  # point to the poller CFG file NOTE this is temp for
testing use above line in live


local $/ = }\n;   # set delimiter


open(POLLER, $NH_HOME/poller.cfg) || die can not open : $!;

#s/universalPollList \{//g;

while(POLLER) {
next unless /^\s+segment/;
s/\n\s+\}\n//g;
s/[{]//g;
foreach (split(/\n/)) {
($nullVar,$segmentFieldKey,$segmentFieldValue) =
split(/\s+/,$_,3);
$segmentFields{ $segmentFieldKey } = $segmentFieldValue ;
}
if ( $segmentFields{$findKey} eq $findValue ) {

push @foundSegments, {%segmentFields } ;
}
undef %segmentFields;
my %segmentFields;
}
close POLLER;

return (@foundSegments);  # return the IP and comunity string to main
ruteen
};

/scanPoller.cfg.pl==


exampleExtract form poller.cfg==

   segment customer-site-Bend {
   agentAddress x.x.x.x
   uniqueDeviceId   dfofdkskhjkldsf
   mibTranslationFile cisco-frameRelay-cir.mtf
   index2
   index2   400
   deviceSpeed  64000.0
   deviceSpeed2 64000.0
   discoverMtf  cisco-frameRelay-cir.mtf
   index3   7
   communitypublic
   sysDescr Cisco Internetwork Operating System Software
IOS (tm) C1700 Software (C1700-Y-M), Version 12.1 blar blar...
   sysName  routerName
   sysLoc   siteLocation
   ifDescr  Serial0
   ifType   frame-relay
   aliasName

RE: how to open a file with 666 permission

2004-09-30 Thread Bob Showalter
Gunnar Hjalmarsson wrote:
 Bob Showalter wrote:
  Chris Devers wrote:
   Maybe the program is a code generator that produces other files
   which should be executable (I can't remember anyone doing this,
   but there's no reason why it couldn't be reasonably be done).
  
  Fine, use creation bits of 0777.
 
 Are you saying that
 
  open FH,  $file;
  chmod 0777, $file;
 
 is fine, while
 
  umask 0;
  sysopen FH, $file, O_CREAT|O_RDWR, 0777;
 
 is not? In that case, I'm really confused by now. ;-)

No, I'm saying that neither is fine. Just pass 0600 or 0777 to open(2) and
let the umask determine the resulting permissions. I don't want the program
to decide for me that the file needs to have world write priv, for example.

I'm still struggling to think of a real-world situation where a file would
_have_ to be created as rw-rw-rw- or rwxrwxrwx.

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: connect through socks

2004-09-30 Thread Jim
  
  Hi perlers,
  
  anyone knows how to connect to a website and download it 
 through socks 
  (ver 4,5) ? I tried IO::Socket::Socks and Net::SOCKS, but I 
 can't get 
  them to work.
 
 I know it can be done via 'LWP::UserAgent'. Not sure via a 
 socket though.

you could always do this:

use Socket;

$port = 80;
$host ='www.somesite.com';
$proto = getprotobyname('tcp');
$addr = gethostbyname($host); 
$ip = join(., unpack(C4, $addr));

my $dest = sockaddr_in($port, inet_aton($ip));
socket(S,AF_INET,SOCK_STREAM, $proto) or die coudn't create sock: $!;  
connect(S,$dest) or die can't connect: $!\n; 

select(S); $| = 1; select(STDOUT);

print S GET / HTTP/1.0\n\n;
print while (S);


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 9/27/2004
 


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-09-30 Thread Randal L. Schwartz
 John == John W Krahn [EMAIL PROTECTED] writes:

John You might hurt his feelings, he didn't contribute to the third edition
John of Programming Perl.

Actually, it's worse than that.  I contributed to it, but wasn't credited
for it or paid for it.

John   Better to buy his latest book _Learning Perl
John Objects, References  Modules_  ;-)

Yes, or Learning Perl.  Both good books, from what I hear.  I dunno,
I write'em, not read 'em. :)

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

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




printing block of text

2004-09-30 Thread Murphy, Ged (Bolton)
I'm trying to print a block of code using 'print LABEL; but am getting an
error stating perl can't find the termination label.
Test code and error as follows:

#!/usr/bin/perl

print TEST;
this is my tester text
TEST

Can't find string terminator TEST anywhere before EOF at photo.pl line 3.


Anyone got any ideas as to why it's doing this?

Thanks.

The information contained in this message or any of its
attachments is confidential and is intended for the exclusive
use of the addressee. The information may also be legally
privileged. The views expressed may not be company policy,
but the personal views of the originator. If you are not the
addressee, any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited.
If you have received this message in error, please contact
[EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] and then delete this message. 

Exide Technologies is an industrial and transportation battery
producer and recycler with operations in 89 countries.
Further information can be found at www.exide.com



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: (when) is the ; required?

2004-09-30 Thread Randal L. Schwartz
 Chris == Chris Devers [EMAIL PROTECTED] writes:

Chris My impression is that the missing semi-colon is allowed to make it so 
Chris that statements like this --

Chris   sub ack { print Ack! Ack! Mars will rule! }

Chris -- work as one-liners without having to fuss over another semi-colon. 
Chris For anything longer than a single-statement one-liner, it's a bad habit.

My rule is that if I'm writing a multi-line block:

if (...) {
...
...
...
}

then I include the final semicolon, but if it's only one line,
I leave it off.

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

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how to open a file with 666 permission

2004-09-30 Thread Gunnar Hjalmarsson
Bob Showalter wrote:
I'm still struggling to think of a real-world situation where a
file would _have_ to be created as rw-rw-rw- or rwxrwxrwx.
There may be a need to grant more than one user write access. CGI
scripts are running as the webserver user by default, and if you let
e.g. sendmail start a process, another user may appear.
Personally I prefer to handle these situations via GID, but you may
not have permissions to create groups and change GID.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: printing block of text

2004-09-30 Thread Gunnar Hjalmarsson
Ged Murphy wrote:
I'm trying to print a block of code using 'print LABEL; but am
getting an error stating perl can't find the termination label.
Test code and error as follows:
#!/usr/bin/perl
print TEST;
this is my tester text
TEST
Can't find string terminator TEST anywhere before EOF at photo.pl
line 3.
Anyone got any ideas as to why it's doing this?
The here-document syntax is described in perldoc perlop, and the
author of that part of the Perl docs had a couple of ideas.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Need help with script

2004-09-30 Thread Errin Larsen
Hi Perlers,

On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro
[EMAIL PROTECTED] wrote:
 On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote:
   I would like the output in the following format
   object1...tabDescription1
   object2...tabDescription2
   object3...tabDescription3
  
  
   perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME
  
  
  
   perl -l -00pe's/\n/\t/' FILENAME
 
  That's pretty slick you guys, he's sure to get an A+ ;)
 
  If your teacher requires the quotes to be removed:
 
 What if the teacher requires an explanation? O:-)
 
 It is my opinion that code should be explained, at least in this list.
  You're trying to teach people how to fish (and maybe swim). Giving them
  fish is good, of course, but tell them how you got it :-)
 
 That said, nice code :-)
 
perl -l -00pe's/\n/\t/;s/\//g;' FILENAME
 
  :)
 -- 
 José Alves de Castro [EMAIL PROTECTED]
   http://natura.di.uminho.pt/~jac
 

I'll give it a try.

First, it's good to know that the two Perl special variables '$/' and
'$\' are the input separator and output separator.  By Default, they
will be $/ = \n (newline character) and $\ = undef (nothing.  No
output separator).

Now, on the command line, the '-0' option will set the input separator
($/).  In the above example, it's setting $/ = 0.  Also, in the
example, the '-l' will do two things.  First, it will automatically
chomp() whatever's in '$/', and then it will set the output separator
to be whatever the input separator will be.  So, specific to our
example, first '-l' sets '$\' (output separator) to whatever '$/' is
(at this point, it's \n, or a newline).  Then, the '-0' switch is
setting the $/ = 0 ( or null, or nothing!).

OK, next we have '-p' and '-e'.  The '-e' tells Perl to read one line
(the one after the '-e') and use that as the code to process.  The
'-p' causes Perl to assume the following code around your code:

LINE:
  while(  ) {
# your code goes here
  } continue {
print or die -p destination: $!\n;
  }

So, this is going to process whatever files it finds on your command
line and then print '$_'!

Now, the code that's going into that block is, in our example:
   s/\n/\t/;
   s/\//g;

So, we get this as the code Perl is running:

LINE:
  while(  ) {
s/\n/\t/;  # Change newlines into tabs
s/\//g;   # Remove all double-quotes
  } continue {
print or die -p destination: $!\n;
  }

but with the special $/ = 0 as the input separator and $\ = \n as the
output separator!

There!  Am I right?  This is fun ... we should do this more often! 
This taught me a lot.

BTW, I found most of these explanations in the 'perldoc perlrun' and
'perldoc perlvar' pages.  You can check out continue blocks with
'perldoc -f continue'.

--Errin

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help with script

2004-09-30 Thread Paul Johnson
On Thu, Sep 30, 2004 at 08:00:41AM -0500, Errin Larsen wrote:

 Hi Perlers,
 On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro
 [EMAIL PROTECTED] wrote:

  On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote:
 perl -l -00pe's/\n/\t/;s/\//g;' FILENAME

  It is my opinion that code should be explained, at least in this list.

And it normally is.  But if someone posts a message saying please do
this for me without (apparently) making any effort to do it themselves,
then a functioning cryptic one-liner response is a succinct way of
saying that as soon as you put a little more effort into this then so
will we.

 So, we get this as the code Perl is running:
 
 LINE:
   while(  ) {
 s/\n/\t/;  # Change newlines into tabs
 s/\//g;   # Remove all double-quotes
   } continue {
 print or die -p destination: $!\n;
   }
 
 but with the special $/ = 0 as the input separator and $\ = \n as the
 output separator!
 
 There!  Am I right?  This is fun ... we should do this more often! 

Pretty close:

$ perl -MO=Deparse -l00pe's/\n/\t/;s/\//g'
BEGIN { $/ = \n; $\ = \000; }
LINE: while (defined($_ = ARGV)) {
chomp $_;
s/\n/\t/;
s///g;
}
continue {
print $_;
}
-e syntax OK

which shows a little confusion over $/ and $\, and an unnecessary \ in the
initial program.

 This taught me a lot.

Good :-)

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: printing block of text

2004-09-30 Thread Murphy, Ged (Bolton)
 I'm trying to print a block of code using 'print LABEL; but am
 getting an error stating perl can't find the termination label.
 Test code and error as follows:
 
 #!/usr/bin/perl
 
 print TEST;
 this is my tester text
 TEST
 
 Can't find string terminator TEST anywhere before EOF at photo.pl
 line 3.
 
 Anyone got any ideas as to why it's doing this?

The here-document syntax is described in perldoc perlop, and the
author of that part of the Perl docs had a couple of ideas.

I've been through the here-documentation in the perlop doc and it appears my
syntax is correct.
Does anyone have any ideas as to why I am getting this error?

Is it possible this is an interpreter error?
I'm running activestate's perl, v5.8.0 built for MSWin32-x86-multi-thread

The information contained in this message or any of its
attachments is confidential and is intended for the exclusive
use of the addressee. The information may also be legally
privileged. The views expressed may not be company policy,
but the personal views of the originator. If you are not the
addressee, any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited.
If you have received this message in error, please contact
[EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] and then delete this message. 

Exide Technologies is an industrial and transportation battery
producer and recycler with operations in 89 countries.
Further information can be found at www.exide.com



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: printing block of text

2004-09-30 Thread Paul Johnson
On Thu, Sep 30, 2004 at 02:39:04PM +0100, Murphy,  Ged (Bolton) wrote:
  I'm trying to print a block of code using 'print LABEL; but am
  getting an error stating perl can't find the termination label.
  Test code and error as follows:
  
  #!/usr/bin/perl
  
  print TEST;
  this is my tester text
  TEST
  
  Can't find string terminator TEST anywhere before EOF at photo.pl
  line 3.
  
  Anyone got any ideas as to why it's doing this?
 
 The here-document syntax is described in perldoc perlop, and the
 author of that part of the Perl docs had a couple of ideas.
 
 I've been through the here-documentation in the perlop doc and it appears my
 syntax is correct.
 Does anyone have any ideas as to why I am getting this error?

Do you have a newline on line 3?

 Is it possible this is an interpreter error?
 I'm running activestate's perl, v5.8.0 built for MSWin32-x86-multi-thread

But no carriage return or other white space?

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: printing block of text

2004-09-30 Thread Gabor Urban
On Thu, 2004-09-30 at 15:39, Murphy, Ged (Bolton) wrote:
  I'm trying to print a block of code using 'print LABEL; but am
  getting an error stating perl can't find the termination label.
  Test code and error as follows:
  
  #!/usr/bin/perl
  
  print TEST;
  this is my tester text
  TEST
  
  Can't find string terminator TEST anywhere before EOF at photo.pl
  line 3.
  
  Anyone got any ideas as to why it's doing this?
 
 The here-document syntax is described in perldoc perlop, and the
 author of that part of the Perl docs had a couple of ideas.
 
 I've been through the here-documentation in the perlop doc and it appears my
 syntax is correct.
 Does anyone have any ideas as to why I am getting this error?
 
 Is it possible this is an interpreter error?
 I'm running activestate's perl, v5.8.0 built for MSWin32-x86-multi-thread
Hi,

your code works fine for my debian box.
--
[EMAIL PROTECTED]:~/Stuff$ perl -v

This is perl, v5.8.3 built for i386-linux-thread-multi
--

Gabaux


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Regex:: using variables to hold replacement text

2004-09-30 Thread William Lewis Brown
Hi,
I have a need to store replacement text for a regex substitution
in a variable.  In other words, I have code in a perl script like so::

$foo =~ s/(.*)bar(.*)/$replacement/g;

The $replacement string needs to contain a reference to $1.  In other
words, the string $replacement will contain the string $1.  I need to
have the $1 string interpreted so that it will be replaced with the text
of the first '(.*)' expression.  I have not yet found a way to get this
to happen.  The $1 string always seems to be interpreted as a plain
string.

Can someone tell me how to write the substitution correctly?  I
have included an example below.

Thanks for your help and your time.


Bill Brown
[EMAIL PROTECTED]

+++

 $ perl -d
  
 Loading DB routines from perl5db.pl version 1.0402
 Emacs support available.
  
 Enter h or `h h' for help.
  
 my $foo=yada bar yada;
 my $replacement='$1';
 $foo =~ s/(.*)bar(.*)/$replacement/g;
 print $foo;
 my $foo=yada bar yada;
 $foo =~ s/(.*)bar(.*)/$1/g;
 print $foo
 main::(-:1):my $foo=yada bar yada;
   DB1 n
 main::(-:2):my $replacement='$1';
   DB1 n
 main::(-:3):$foo =~ s/(.*)bar(.*)/$replacement/g;
   DB1 n
 main::(-:4):print $foo;
   DB2 n
 $1[ BAD OUTPUT ]
 main::(-:5):  my $foo=yada bar yada;
   DB2 n
 main::(-:6):$foo =~ s/(.*)bar(.*)/$1/g;
   DB2 n
 main::(-:7):print $foo
   DB2 n
 yada [ GOOD OUTPUT]
 Debugged program terminated.  Use q to quit or R to restart,
   use O inhibit_exit to avoid stopping after program termination,
   h q, h R or h O to get additional info.
   DB2

-- 
William L. Brown
Email: [EMAIL PROTECTED]



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: printing block of text

2004-09-30 Thread Murphy, Ged (Bolton)
Hi,

your code works fine for my debian box.
--
[EMAIL PROTECTED]:~/Stuff$ perl -v

This is perl, v5.8.3 built for i386-linux-thread-multi
--

Must be the interpreter then. That is weird.
This is being written for a Linux box so I'll just comment it out until
then.

Thanks.


The information contained in this message or any of its
attachments is confidential and is intended for the exclusive
use of the addressee. The information may also be legally
privileged. The views expressed may not be company policy,
but the personal views of the originator. If you are not the
addressee, any disclosure, reproduction, distribution or other
dissemination or use of this communication is strictly prohibited.
If you have received this message in error, please contact
[EMAIL PROTECTED] 
mailto:[EMAIL PROTECTED] and then delete this message. 

Exide Technologies is an industrial and transportation battery
producer and recycler with operations in 89 countries.
Further information can be found at www.exide.com



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: printing block of text

2004-09-30 Thread Chris Devers
On Thu, 30 Sep 2004, Murphy,  Ged (Bolton) wrote:

 I'm trying to print a block of code using 'print LABEL; but am
 getting an error stating perl can't find the termination label.
 Test code and error as follows:
 
 #!/usr/bin/perl
 
 print TEST;
 this is my tester text
 TEST
 
 Can't find string terminator TEST anywhere before EOF at photo.pl
 line 3.

Weird bugs like this were what made me stop using heredocs in most 
cases. I find multi-line q{} blocks much more readable:

#!/usr/bin/perl

print qq[
this is my first tester text, with double-quotes
];

print q{
this is my second tester text [with 'single-quotes']
};

This way, most text editors tend to be able to pick up the string 
terminating characters () [] {} and help make sure that things remain 
balanced. I've had better luck this way than I ever did with heredocs.


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Regex:: using variables to hold replacement text

2004-09-30 Thread Gunnar Hjalmarsson
William Lewis Brown wrote:
I have a need to store replacement text for a regex substitution in
a variable.  In other words, I have code in a perl script like so::
$foo =~ s/(.*)bar(.*)/$replacement/g;
The $replacement string needs to contain a reference to $1.  In
other words, the string $replacement will contain the string $1.
I need to have the $1 string interpreted so that it will be
replaced with the text of the first '(.*)' expression.
You are asking a FAQ.
perldoc -q expand variables
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: GetOptions problems

2004-09-30 Thread Wiggins d Anconia
 
 
 Hello Perl type people
 
  i am shore i had this working, but its all gone wrong for some resion the
 options do not seem to be getting filled.


Actually you were probably 'sure', and it is probably failing for some
'reason'.
 
  can some one please help
 

'someone' probably will help, but I don't think there are any 'one's here.

 the program is for searching through a large datafile (poller.cfg)
 and outputting the found data in a more usefull format.
 

or even a 'useful' format.

 BTW i am not getting payed to dev this script it just make my job eayeser

Nope not 'payed' but possibly 'paid', and very rarely would anyone pay
to 'dev' a script as opposed to 'develop' one. and it probably 'makes'
your job 'easier'.

 and i get to try and lern perl too.

Hopefully you are 'learn'ing Perl.

 i guess this should all be structured better so if you have any
 constructive comments =)

Start with a spell checker, use punctuation, work on the grammar.  Have
a look at:

http://www.catb.org/~esr/faqs/smart-questions.html#writewell

Specifically,

Write in clear, grammatical, correctly-spelled language

We've found by experience that people who are careless and sloppy
writers are usually also careless and sloppy at thinking and coding
(often enough to bet on, anyway). Answering questions for careless and
sloppy thinkers is not rewarding; we'd rather spend our time elsewhere.

So expressing your question clearly and well is important. If you can't
be bothered to do that, we can't be bothered to pay attention. 

The whole page has valuable insights.

 
 thank you.
 RichT
 
 
 /scanPoller.cfg.pl==
  more scanPoller.cfg.pl
 #!/usr/local/bin/perl
 #
 
 use strict;
 use warnings;
 use Getopt::Long;
 
 my

($inFile,$USAGE,$showKey,$site,$found,$foundKeys,@dataFile,@foundSegments,$value);

Declaring all of your variables up front defeats the purpose of 'strict'
and makes it far less useful. You should declare your variables at first
usage and in the proper scopes.


 my ($opt_inFile, $opt_listAllFields, $opt_help ) = (0,0,0);
 my $opt_findField = agentAddress;
 my $opt_showFields = segment,agentAddress,community;
 
 $USAGE = USAGETEXT;
 usage: $0 ipaddress
   the following options are also availble
   [-inFile filename ] input filename
   [-findField fieldName ] this is the search key (default is
 agentAddress)
   [-showFields field names ] feilds to output (default is
 segment,agentAddress,community)
   [-listAllFields ] list avalible fields
   [-help] this help text
 USAGETEXT
 

The above is ok, but you might consider taking the advice of the
Getopt::Long docs and using Pod::Usage to generate error messages and
help text via pod.

 GetOptions(inFile=s,
 findField=s,
 showFields=s,
 listAllFields,
 help|h|H|?|HELP,
 );
 

You should drop the C it is not needed in this context. You should
also go back to the docs for Getopt::Long, it does not have the default
$opt_ variables for the options, it instead uses references or a hash. I
assume this is left over from Getopt::Std, and in that case you would
have to declare your $opt_ variables with Cour instead of Cmy.

 print  listAllFields =$opt_listAllFields\n;  #testing
 print  help =$opt_help\n;  #testing
 

Docs can be found at 
http://search.cpan.org/~jv/Getopt-Long-2.34/lib/Getopt/Long.pm

And I have an example template that uses Getopt::Long and incorporates
Pod::Usage available here:

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

snip

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Trouble with m///g

2004-09-30 Thread Chap Harrison
Hi,
I'm trying to extract all four-digit numbers from a string in one fell 
swoop, but I can't seem to come up with the proper regexp.  This is my 
first time using /g in a match so maybe there's a trick I'm missing.

For example, the string
 aa 444   -
should yield
, , , , , .
Here's one attempt that I thought had a reasonable chance.
- - - - -
#!/usr/bin/perl -w
my $foo =  aa 444   -;
my @a = ($foo =~ m'[\D^](\d{4})[\D$]'g);
print $foo\n;
print(join(:,@a).\n);
- - - - -
 aa 444   -
::
Thanks for your consideration,
Chap
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Trouble with m///g

2004-09-30 Thread Hanson, Rob
I think this might work.

/\b\d{4}\b/

Rob

-Original Message-
From: Chap Harrison [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 30, 2004 10:38 AM
To: [EMAIL PROTECTED]
Subject: Trouble with m///g


Hi,

I'm trying to extract all four-digit numbers from a string in one fell 
swoop, but I can't seem to come up with the proper regexp.  This is my 
first time using /g in a match so maybe there's a trick I'm missing.

For example, the string

 aa 444   -

should yield

, , , , , .

Here's one attempt that I thought had a reasonable chance.

- - - - -
#!/usr/bin/perl -w
my $foo =  aa 444   -;
my @a = ($foo =~ m'[\D^](\d{4})[\D$]'g);
print $foo\n;
print(join(:,@a).\n);
- - - - -

 aa 444   -
::

Thanks for your consideration,
Chap


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-09-30 Thread Craig Harmon
I love your sense of humor! Made my morning.
Randal L. Schwartz wrote:
John == John W Krahn [EMAIL PROTECTED] writes:

John You might hurt his feelings, he didn't contribute to the third edition
John of Programming Perl.
Actually, it's worse than that.  I contributed to it, but wasn't credited
for it or paid for it.
John   Better to buy his latest book _Learning Perl
John Objects, References  Modules_  ;-)
Yes, or Learning Perl.  Both good books, from what I hear.  I dunno,
I write'em, not read 'em. :)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Trouble with m///g

2004-09-30 Thread Dave Gray
 For example, the string
 
  aa 444   -
 
 should yield
 
 , , , , , .

That's actually kind of tricky. How about:

$aa =  aa 444   -;
@aa = $aa =~ /(?!\d)\d{4}(?!\d)/g;
print $_\n for @aa;

That gets  and  also, which the \b solution skips. What it
says is to get all groups of 4 numbers not following or followed by
another number.

Dave

ps - also see perldoc -f perlre and look for zero-width negative
look(ahead|behind) assertions

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Trouble with m///g

2004-09-30 Thread Wiggins d Anconia
Please bottom post...

 I think this might work.
 

It might, but doesn't. Some testing would be good before posting
inaccurate responses.

 /\b\d{4}\b/
 

\b is matching on boundaries, so you miss the first set, and the set
with the 'aa' around them, and then there is the set with the '-'

 Rob
 
 -Original Message-
 From: Chap Harrison [mailto:[EMAIL PROTECTED]
 Sent: Thursday, September 30, 2004 10:38 AM
 To: [EMAIL PROTECTED]
 Subject: Trouble with m///g
 
 
 Hi,
 
 I'm trying to extract all four-digit numbers from a string in one fell 
 swoop, but I can't seem to come up with the proper regexp.  This is my 
 first time using /g in a match so maybe there's a trick I'm missing.
 
 For example, the string
 
  aa 444   -
 
 should yield
 
 , , , , , .
 
 Here's one attempt that I thought had a reasonable chance.
 
 - - - - -
 #!/usr/bin/perl -w
 my $foo =  aa 444   -;
 my @a = ($foo =~ m'[\D^](\d{4})[\D$]'g);
 print $foo\n;
 print(join(:,@a).\n);
 - - - - -
 
  aa 444   -
 ::
 
 Thanks for your consideration,
 Chap
 

Out of curiousity based on your description shouldn't it return,

:::::::

Or do you really mean, you are trying to capture all 4 digit strings
that are not in a string of longer digits?  You need to be very explicit
about what you are after.  I think (and have tested) that,

my @a = ($foo =~ m'(?!\d{4})\d{4}(?!\d)'g);

Gives you want you want, though I don't claim to be a regex expert like
others on the list (are experts, rather than claiming). And I *believe*
says, match any 4 digit string not preceded by a 4 digit string and not
followed by a digit.

Works?

http://danconia.org



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Trouble with m///g

2004-09-30 Thread Chap Harrison
Hmmm...
m'\b(\d{4})\b'g
 aa 444   -
:::
Doesn't give me  or .  I think the problem has to do with where 
m///g starts on subsequent iterations.  The pattern specifies a 
delimiter for both the start and the end of the target substring, but 
that means it will want to find an ending delim on iteration n, 
followed by a beginning delim on iteration n+1.

On Sep 30, 2004, at 9:41 AM, Hanson, Rob wrote:
I think this might work.
/\b\d{4}\b/
Rob
-Original Message-
From: Chap Harrison [mailto:[EMAIL PROTECTED]
Sent: Thursday, September 30, 2004 10:38 AM
To: [EMAIL PROTECTED]
Subject: Trouble with m///g
Hi,
I'm trying to extract all four-digit numbers from a string in one fell
swoop, but I can't seem to come up with the proper regexp.  This is my
first time using /g in a match so maybe there's a trick I'm missing.
For example, the string
 aa 444   -
should yield
, , , , , .
Here's one attempt that I thought had a reasonable chance.
- - - - -
#!/usr/bin/perl -w
my $foo =  aa 444   -;
my @a = ($foo =~ m'[\D^](\d{4})[\D$]'g);
print $foo\n;
print(join(:,@a).\n);
- - - - -
 aa 444   -
::
Thanks for your consideration,
Chap
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



RE: Need help with script

2004-09-30 Thread Charles K. Clarkson
From: Errin Larsen mailto:[EMAIL PROTECTED] wrote:

[snip]
: There!  Am I right?  This is fun ... we should do this
: more often! This taught me a lot.

That's one advantage of answering questions on a list
like this. You learn while researching the answer. Most of
my experience with perl comes from researching answers to
beginner questions on these lists.


HTH,

Charles K. Clarkson
-- 
Mobile Homes Specialist
254 968-8328



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Regex:: using variables to hold replacement text

2004-09-30 Thread Bob Showalter
William Lewis Brown wrote:
 Hi,
 I have a need to store replacement text for a regex
 substitution in a variable.  In other words, I have code in a perl
 script like so:: 
 
 $foo =~ s/(.*)bar(.*)/$replacement/g;
 
 The $replacement string needs to contain a reference to $1.  In
 other words, the string $replacement will contain the string $1.  I
 need to have the $1 string interpreted so that it will be replaced
 with the text of the first '(.*)' expression.  I have not yet found a
 way to get this to happen.  The $1 string always seems to be
 interpreted as a plain string.

You need to use eval and /e

$foo =~ s/(.*)bar(.*)/eval $replacement/ge;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Trouble with m///g

2004-09-30 Thread Bob Showalter
Chap Harrison wrote:
 Hi,
 
 I'm trying to extract all four-digit numbers from a string in one fell
 swoop, but I can't seem to come up with the proper regexp.  This is my
 first time using /g in a match so maybe there's a trick I'm missing.
 
 For example, the string
 
  aa 444   -
 
 should yield
 
 , , , , , .

TIMTOWTDI:

  @list = grep length==4, /\d+/g

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Trouble with m///g

2004-09-30 Thread Gunnar Hjalmarsson
Chap Harrison wrote:
I'm trying to extract all four-digit numbers from a string in one fell 
swoop, but I can't seem to come up with the proper regexp.  This is my 
first time using /g in a match so maybe there's a trick I'm missing.

For example, the string
 aa 444   -
should yield
, , , , , .
Here's one attempt that I thought had a reasonable chance.
- - - - -
#!/usr/bin/perl -w
my $foo =  aa 444   -;
my @a = ($foo =~ m'[\D^](\d{4})[\D$]'g);
The first character class requires that the number is preceeded by a 
non-digit character. (The ^ character has no special meaning in a 
character class.) Since the first number is not preceeded by anything, 
 is not matched.

I suppose you meant to do:
my @a = ($foo =~ m'(?:\D|^)(\d{4})(?:\D|$)'g);
which gives
:::
but that's not what you want either. The reason why e.g.  is not 
matched is that the space after  is included in the first match, 
so the second attempt to match starts at the first '2'...

You'd better use extended patterns, i.e. zero-width assertions:
my @a = $foo =~ /(?!\d)\d{4}(?!\d)/g;
Read about extended patterns in perldoc perlre.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Trouble with m///g

2004-09-30 Thread Chap Harrison
On Sep 30, 2004, at 9:55 AM, Wiggins d Anconia wrote:
Out of curiousity based on your description shouldn't it return,
:::::::
Or do you really mean, you are trying to capture all 4 digit strings
that are not in a string of longer digits?  You need to be very 
explicit
about what you are after.


The example was intended to resolve the ambiguities of my informal 
description :-)   You correctly surmised what I was after.

my @a = ($foo =~ m'(?!\d{4})\d{4}(?!\d)'g);
And your solution works.  Now I'm going to study up on *how* it works!
Thanks, and also thanks to Dave and Gunnar for what appears to be the 
same solution, and the references to extended patterns and zero-width 
assertions.

Chap
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Help needed: urgent

2004-09-30 Thread Rohit RS
==
Using DBI Perl Programming I get a database o/p as
below
Student SubjectCodeMarks

A   190
A   289
B   170
B   271
B   371
C   273
C   397
-
Subject code may vary to any value.
I need a report o/p in the following format and
displayed in HTML
Student 1   2  3  4   

A  90  89 
B  70  71  71
C  73  97
-

The following code works out  well for this
  $sth-bind_columns (\$Student, \$subjectCode,
\$marks);
  # chuck all the data into an array
  my @ora_data;
  my $index=0;
  my $count=1;
  while ($sth-fetch) #fetching the first row
  {
#If its the first record assign the student id to
the first row
if ($count == 1) {
$ora_data[$index]{'STUDENT'} = $student;
$count++;
}
#Compare the student id of the array with the row
fetched from the 
database
#if its not equal then create the next row in the
array and assign 
the student to the row
if ( $ora_data[$index]{'STUDENT'} ne $student) {
$index++;
$ora_data[$index]{'STUDENT'} = $student;
  }
#If the studentid in the array is equal to the row
fetched from the 
database i.e sth-fetch
#Compare the subject code and assign the
appropriate value of marks 
to the studentid.
   if ($ora_data[$index]{'STUDENT'} eq $student) {
   if ($subjectCode == 1) {
$ora_data[$index]{'MARK1'} = $marks;
}
elsif ($subjectCode == 2) {
$ora_data[$index]{'MARK2'} = $marks;
}
elsif ($subjectCode == 3) {
$ora_data[$index]{'MARK3'} = $marks;
}
elsif ($subjectCode == 512) {
$ora_data[$index]{'MARK4'} = $marks;
}
  }
  }
  # close statement handler and pass the results back.
  $sth-finish;
  return @ora_data;
=
Is there any other way in which this could be coded
efficiently.
Regards
Rohit
-




Yahoo! India Matrimony: Find your partner online. 
http://yahoo.shaadi.com/india-matrimony/

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Trouble with m///g

2004-09-30 Thread Dave Gray
 TIMTOWTDI:
 
   @list = grep length==4, /\d+/g

Shouldn't that be:

 @list = grep length==4, $foo =~ /\d+/g;

Cool solution, I wouldn't have thought to do it that way. I'm getting
varying Benchmarking results, though. I think it might have something
to do with grep speedups from 5.6.1 to 5.8.0... can anyone confirm
this?

On a box with 4 Xeon 2gigs with 5.6.1 and Benchmark v1:
  Rate   grep wregex  regex
grep   55586/s --   -13%   -23%
wregex 64061/s15% --   -12%
regex  72569/s31%13% --

But, on another box with 1 AMD 1gig with 5.8.0 and Benchmark v1.0501:
  Rate wregex  regex   grep
wregex 31437/s --   -14%   -18%
regex  36470/s16% ---5%
grep   38212/s22% 5% --


Confusing!

#!/usr/bin/perl -w
use strict;
use Benchmark qw/cmpthese/;

my ($aa);
$aa =  aa 444   -;

sub regex { my @aa = $aa =~ /(?!\d)\d{4}(?!\d)/g }

# Wiggins ;-)
sub wregex { my @aa = $aa =~ /(?!\d{4})\d{4}(?!\d{4})/g }

sub grep { my @aa = grep length==4, $aa =~ /\d+/g }

cmpthese(10, {
  regex = \regex,
  wregex = \wregex,
  grep  = \grep,
});

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Trouble with m///g

2004-09-30 Thread Jan Eden
Chap Harrison wrote on 30.09.2004:


On Sep 30, 2004, at 9:55 AM, Wiggins d Anconia wrote:

 Out of curiousity based on your description shouldn't it return,

 :::::::

 Or do you really mean, you are trying to capture all 4 digit strings
 that are not in a string of longer digits?  You need to be very 
 explicit
 about what you are after.



The example was intended to resolve the ambiguities of my informal 
description :-)   You correctly surmised what I was after.

 my @a = ($foo =~ m'(?!\d{4})\d{4}(?!\d)'g);

Careful, you mistyped the original proposition:

my @a = ($foo =~ m'(?!\d)\d{4}(?!\d)'g);

This one will find a string consisting of four digits, neither preceded nor followed 
by a digit. In other words: exactly four digits. Your quote will find a string of four 
digits not preceded by another four digits, so it could find a string of five, six or 
seven digits.

- Jan
-- 
How many Microsoft engineers does it take to screw in a lightbulb? None. They just 
redefine dark as the new standard.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




GetOptions problems

2004-09-30 Thread cats
ok ill send again from the correct address...

Actually you were probably 'sure', and it is probably failing for some
'reason'.
...

Start with a spell checker, use punctuation, work on the grammar.  Have
a look at:

yes i know i can not spell, im a dislexic moron
thank you i will read the page from the link.




 thank you.
 RichT


 /scanPoller.cfg.pl==
  more scanPoller.cfg.pl
 #!/usr/local/bin/perl
 #

 use strict;
 use warnings;
 use Getopt::Long;

 my

($inFile,$USAGE,$showKey,$site,$found,$foundKeys,@dataFile,@foundSegments,$value);

Declaring all of your variables up front defeats the purpose of 'strict'
and makes it far less useful. You should declare your variables at first
usage and in the proper scopes.

are i allways beleaved you should declare them like this...
how should i?? some thing like:

my $USAGE = ...

and will this work if the first time the variables is used is in a loop?

 my ($opt_inFile, $opt_listAllFields, $opt_help ) = (0,0,0);
 my $opt_findField = agentAddress;
 my $opt_showFields = segment,agentAddress,community;

 $USAGE = USAGETEXT;
 usage: $0 ipaddress
   the following options are also availble
   [-inFile filename ] input filename
   [-findField fieldName ] this is the search key (default is
 agentAddress)
   [-showFields field names ] feilds to output (default is
 segment,agentAddress,community)
   [-listAllFields ] list avalible fields
   [-help] this help text
 USAGETEXT


The above is ok, but you might consider taking the advice of the
Getopt::Long docs and using Pod::Usage to generate error messages and
help text via pod.

ill look in to this. i have been using O'reilly's Programming Perl
/Learning Perl which say nothing of using Pod

 GetOptions(inFile=s,
 findField=s,
 showFields=s,
 listAllFields,
 help|h|H|?|HELP,
 );


You should drop the C it is not needed in this context. You should
also go back to the docs for Getopt::Long, it does not have the default
$opt_ variables for the options, it instead uses references or a hash. I
assume this is left over from Getopt::Std, and in that case you would
have to declare your $opt_ variables with Cour instead of Cmy.



 print  listAllFields =$opt_listAllFields\n;  #testing
 print  help =$opt_help\n;  #testing


Docs can be found at
http://search.cpan.org/~jv/Getopt-Long-2.34/lib/Getopt/Long.pm

And I have an example template that uses Getopt::Long and incorporates
Pod::Usage available here:

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

snip

http://danconia.org



ok i have had a look at the cpan doc and made some adjustments...
it will take me a while to digest the pod bit though


also i am having a problem with the
#Data collections / inputfile part

foreach $value (@dataFile) {  # loop  for each line/site in dataFile
chomp $value ;
@foundSegments=findVars($searchKey,$value);


it is only storing the last value should i be doing something like

@foundSegments[$i]=findVars($searchKey,$value);
$i++

thank you for your help...

RichT

New code===
#!/usr/local/bin/perl
#

use strict;
use warnings;
use Getopt::Long;

Getopt::Long::config qw(no_ignore_case);

my
($inFile,$USAGE,$showKey,$site,$found,$foundKeys,@dataFile,@foundSegments,$value);

$USAGE = USAGETEXT;
usage: $0 ipaddress
  the following options are also availble
  [-inFile filename ] input filename
  [-findField fieldName ] this is the search key (default is
agentAddress)
  [-showFields field names ] feilds to output (default is
segment,agentAddress,communi
ty)
  [-listAllFields ] list avalible fields
  [-help] this help text
USAGETEXT
my $needHelp = '' ;
my $outputAllFields = '' ;
my $inputFile = '' ;
my $searchKey = agentAddress;
my $outputFields = segment,agentAddress,community;

GetOptions( inFile=s  = \$inputFile,
findField=s   = \$searchKey,
showFields=s  = \$outputFields,
listAllFields = \$outputAllFields,
help|h|H|?|HELP   = \$needHelp
);

if ($needHelp) {print $USAGE; exit; } # check to see if this is a request
for help, if so prin
t USAGE


# Data collections
#   if we using an input file?
#   else if we have found some values on the cl
#   else quit


if ($inputFile){  # find  results if we have in -inFile

open DFILE, $inputFile  # open $inputFile and read in  or die
or die  could not open $inputFile;
@dataFile = DFILE;
close DFILE;

foreach $value (@dataFile) {  # loop  for each line/site in 

Re: Help needed: urgent

2004-09-30 Thread Wiggins d Anconia
 ==
 Using DBI Perl Programming I get a database o/p as
 below
 Student SubjectCodeMarks
 
 A   190
 A   289
 B   170
 B   271
 B   371
 C   273
 C   397
 -
 Subject code may vary to any value.
 I need a report o/p in the following format and
 displayed in HTML
 Student 1   2  3  4   
 
 A  90  89 
 B  70  71  71
 C  73  97
 -
 

I am not sure why you chose an array as your top level structure.
Assuming each student is unique, and each subject is unique, you can use
a hash of students, with the values of that being a hash of subjects,
with the value being the mark. This eliminates the need for all the
index munging.  For me it would look something like:

use strict;
use warnings;

my $sth = [

{ 'student' = 'A', 'subject' = '1', 'mark' ='90' },
{ 'student' = 'A', 'subject' = '2', 'mark' ='89' },
{ 'student' = 'B', 'subject' = '1', 'mark' ='70' },
{ 'student' = 'B', 'subject' = '2', 'mark' ='71' },
{ 'student' = 'B', 'subject' = '3', 'mark' ='71' },
{ 'student' = 'C', 'subject' = '2', 'mark' ='73' },
{ 'student' = 'C', 'subject' = '3', 'mark' ='97' },

];

my $students;
foreach my $row (@$sth) {
#while (my $row = $sth-fetchrow_hashref) {
$students-{$row-{'student'}}-{$row-{'subject'}} = $row-{'mark'};
}

foreach my $student (sort keys %$students) {
print $student, \t;
foreach my $subject (sort keys %{$students-{$student}}) {
print \t, $students-{$student}-{$subject};
}
print \n;
}

I have simulated your select above with the data you provided, switch
the Cforeach to the commented Cwhile to have it use the actual
statement handle.

You can use Cprintf or formats to get the columns to line up right.

snip code

 =
 Is there any other way in which this could be coded
 efficiently.
 Regards
 Rohit

There is always another way. Better is always debatable

Some Lite reading:

perldoc perllol
perldoc perldsc
perldoc perlreftut
perldoc perlref

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Trouble with m///g

2004-09-30 Thread Chap Harrison
On Sep 30, 2004, at 10:41 AM, Jan Eden wrote:
my @a = ($foo =~ m'(?!\d{4})\d{4}(?!\d)'g);

Careful, you mistyped the original proposition:
my @a = ($foo =~ m'(?!\d)\d{4}(?!\d)'g);
Oops, sorry - I copied that into the email from Wiggins' reply, but 
actually tested with Dave Gray's.  Didn't notice the difference.  What 
you posted gives the solution I was after.  Thanks for the scrutiny!

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Open a text file

2004-09-30 Thread Jenda Krynicky
From: Eduardo Vzquez Rodrguez
[EMAIL PROTECTED]
 Thanks Chris I try this and works

$. = 0;
  do
  {
  $_ = INPUT
  }
  until $. == 5;

Looks a bit too involved. Why not just

INPUT for (1..5);

?

 WHILE INPUT

I believe you meant
while (INPUT)

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]
http://learn.perl.org/ http://learn.perl.org/first-response




how do i describe a perl user?

2004-09-30 Thread Sano Babu
just wondering what a user of Perl may be called? Perler?? Theres
got to be some fancy name for it. Perl is not just another programming
language.. I reckon its much more like a religion with attitude.. :)

Cheers,
SanoBabu

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: GetOptions problems

2004-09-30 Thread Wiggins d Anconia
 ok ill send again from the correct address...
 
 Actually you were probably 'sure', and it is probably failing for some
 'reason'.
 ...
 
 Start with a spell checker, use punctuation, work on the grammar.  Have
 a look at:
 
 yes i know i can not spell, im a dislexic moron
 thank you i will read the page from the link.


Dyslexia does not make one a moron, though it must make programming
significantly more challenging. I thought something might be up, which
is why my comments were made, but not intentionally hurtful. Sometimes
people really are that lazy
 
 
 
 
  thank you.
  RichT
 
 
  /scanPoller.cfg.pl==
   more scanPoller.cfg.pl
  #!/usr/local/bin/perl
  #
 
  use strict;
  use warnings;
  use Getopt::Long;
 
  my
 

($inFile,$USAGE,$showKey,$site,$found,$foundKeys,@dataFile,@foundSegments,$value);
 
 Declaring all of your variables up front defeats the purpose of 'strict'
 and makes it far less useful. You should declare your variables at first
 usage and in the proper scopes.
 
 are i allways beleaved you should declare them like this...
 how should i?? some thing like:
 
 my $USAGE = ...
 
 and will this work if the first time the variables is used is in a loop?

Yes. There is no hard rule, the variable should be declared at the
tightest scope possible. So if the variable is only needed in a loop,
then declare it in the loop. If it needs a less specific scope, then
scope it where you need to.  For more on scoping check out:

http://perl.plover.com/FAQs/Namespaces.html


 
  my ($opt_inFile, $opt_listAllFields, $opt_help ) = (0,0,0);
  my $opt_findField = agentAddress;
  my $opt_showFields = segment,agentAddress,community;
 
  $USAGE = USAGETEXT;
  usage: $0 ipaddress
the following options are also availble
[-inFile filename ] input filename
[-findField fieldName ] this is the search key (default is
  agentAddress)
[-showFields field names ] feilds to output (default is
  segment,agentAddress,community)
[-listAllFields ] list avalible fields
[-help] this help text
  USAGETEXT
 
 
 The above is ok, but you might consider taking the advice of the
 Getopt::Long docs and using Pod::Usage to generate error messages and
 help text via pod.
 
 ill look in to this. i have been using O'reilly's Programming Perl
 /Learning Perl which say nothing of using Pod
 

Yes the first is a reference about language features rather than a good
source of best practices, the second is excellent for teaching, but as
such tends to keep snippets short in the interest of teaching the
specific subject at hand. Both are excellent for their intended purpose,
which is not always developing full programs.

  GetOptions(inFile=s,
  findField=s,
  showFields=s,
  listAllFields,
  help|h|H|?|HELP,
  );
 
 
 You should drop the C it is not needed in this context. You should
 also go back to the docs for Getopt::Long, it does not have the default
 $opt_ variables for the options, it instead uses references or a hash. I
 assume this is left over from Getopt::Std, and in that case you would
 have to declare your $opt_ variables with Cour instead of Cmy.
 
 
 
  print  listAllFields =$opt_listAllFields\n;  #testing
  print  help =$opt_help\n;  #testing
 
 
 Docs can be found at
 http://search.cpan.org/~jv/Getopt-Long-2.34/lib/Getopt/Long.pm
 
 And I have an example template that uses Getopt::Long and incorporates
 Pod::Usage available here:
 

http://danconia.org/cgi-bin/request?handler=Content;content=StaticPage;label=getopt_long_template
 
 snip
 
 http://danconia.org
 
 
 
 ok i have had a look at the cpan doc and made some adjustments...
 it will take me a while to digest the pod bit though
 

They often do, being able to read the docs and pull from the API is
probably the most important skill in Perl (programming in general).

 
 also i am having a problem with the
 #Data collections / inputfile part
 
 foreach $value (@dataFile) {  # loop  for each line/site in
dataFile
 chomp $value ;
 @foundSegments=findVars($searchKey,$value);
 

Generally when looping over a file you should use a Cwhile construct
instead to reduce memory overhead. 

 
 it is only storing the last value should i be doing something like
 
 @foundSegments[$i]=findVars($searchKey,$value);
 $i++

This would be a very C way of doing it, which is ok, but in Perl we are
provided with the Cpush function, which is signifcantly easier,

perldoc -f push

push @foundSegments, findVars($searchKey, $value);

 
 thank you for your help...
 
 RichT

Keep at it...

http://danconia.org

 
 New code===
snip

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: GetOptions problems

2004-09-30 Thread Chap Harrison
On Sep 30, 2004, at 10:35 AM, cats wrote:
yes i know i can not spell, im a dislexic moron
If you're like other dyslexics I've known, you're probably (a) not a 
moron and (b) exceptionally brilliant in other areas.

Thanks for the reminder.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Need help with script

2004-09-30 Thread Errin Larsen
Hi Paul,
Thx for the response

On Thu, 30 Sep 2004 15:30:06 +0200, Paul Johnson [EMAIL PROTECTED] wrote:
 
SNIP

 
 Pretty close:
 
 $ perl -MO=Deparse -l00pe's/\n/\t/;s/\//g'
 BEGIN { $/ = \n; $\ = \000; }
 LINE: while (defined($_ = ARGV)) {
 chomp $_;
 s/\n/\t/;
 s///g;
 }
 continue {
 print $_;
 }
 -e syntax OK
 
 which shows a little confusion over $/ and $\, and an unnecessary \ in the
 initial program.
 
  This taught me a lot.
 
 Good :-)
 
 --
 Paul Johnson - [EMAIL PROTECTED]


When I run your command line up there, I get the following:

# perl -MO=Deparse -l00pe's/\n/\t/;s/\//g'
LINE: while (defined($_ = ARGV)) {
chomp $_;
s/\n/\t/;
s///g;
}
continue {
print $_;
}
-e syntax OK

What OS are you running?  My '-MO=Deparse' didn't create that BEGIN
Block.  I'm on Solaris, using Perl 5.6.1.  I'm just curious what the
difference is.

--Errin

BTW, I didn't know about the Deparse Pre-Compiler thing!  Thanks for
pointing it out.  It's very handy.  Why do you think Perl uses:

  while( defined( $_ = ARGV ) )

instead of:
  
  while(  )

Is this example pointing out that the diamond (  ) operator is
really a short-cut for 'defined( $_ = ARGV )' ?  I'll have to go
read about this.  What is Perl protecting against by putting that
assignment in a defined()?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how do i describe a perl user?

2004-09-30 Thread Errin Larsen
On Fri, 1 Oct 2004 01:37:44 +0930, Sano Babu [EMAIL PROTECTED] wrote:
 just wondering what a user of Perl may be called? Perler?? Theres
 got to be some fancy name for it. Perl is not just another programming
 language.. I reckon its much more like a religion with attitude.. :)
 
 Cheers,
 SanoBabu
 

I say 'Perler' when I'm addressing this list.  Haven't had anyone
complain yet!  I haven't seen anything else!  Anyone else have some
suggestions?  The 'Guru's on the web are at a site called Perl
Monks.  But what do you call a devotee, not a guru?

--Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how do i describe a perl user?

2004-09-30 Thread Wiggins d Anconia
 On Fri, 1 Oct 2004 01:37:44 +0930, Sano Babu [EMAIL PROTECTED] wrote:
  just wondering what a user of Perl may be called? Perler?? Theres
  got to be some fancy name for it. Perl is not just another programming
  language.. I reckon its much more like a religion with attitude.. :)
  
  Cheers,
  SanoBabu
  
 
 I say 'Perler' when I'm addressing this list.  Haven't had anyone
 complain yet!  I haven't seen anything else!  Anyone else have some
 suggestions?  The 'Guru's on the web are at a site called Perl
 Monks.  But what do you call a devotee, not a guru?
 
 --Errin
 

Where there is 'JAPH' but that tends to have another meaning as well

Considering readability is often a goal in Perl, why not call them a
user of Perl... or if you are into the whole brevity thing, a Perl
Programmer.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how do i describe a perl user?

2004-09-30 Thread Jose Alves de Castro
On Thu, 2004-09-30 at 17:07, Sano Babu wrote:
 just wondering what a user of Perl may be called?

I would call him a very intelligent person O:-)

 Perler?? Theres
 got to be some fancy name for it. Perl is not just another programming
 language.. I reckon its much more like a religion with attitude.. :)

OK, a bit more seriously, now: Perl hacker and Perl monger are
 frequently used...

Would anyone more experienced than me care to send his two cents on this
 one? :-)

 Cheers,
 SanoBabu
-- 
José Alves de Castro [EMAIL PROTECTED]
  http://natura.di.uminho.pt/~jac


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help with script

2004-09-30 Thread PerlDiscuss - Perl Newsgroups and mailing lists
Paul Johnson wrote:

 On Thu, Sep 30, 2004 at 08:00:41AM -0500, Errin Larsen wrote:

  Hi Perlers,
  On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro
  [EMAIL PROTECTED] wrote:

   On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote:
  perl -l -00pe's/n/t/;s///g;' FILENAME

   It is my opinion that code should be explained, at least in this list.

 And it normally is.  But if someone posts a message saying please do
 this for me without (apparently) making any effort to do it themselves,
 then a functioning cryptic one-liner response is a succinct way of
 saying that as soon as you put a little more effort into this then so
 will we.

  So, we get this as the code Perl is running:
  
  LINE:
while(  ) {
  s/n/t/;  # Change newlines into tabs
  s///g;   # Remove all double-quotes
} continue {
  print or die -p destination: $!n;
}
  
  but with the special $/ = 0 as the input separator and $ = n as the
  output separator!
  
  There!  Am I right?  This is fun ... we should do this more often! 

 Pretty close:

 $ perl -MO=Deparse -l00pe's/n/t/;s///g'
 BEGIN { $/ = n; $ = 00; }
 LINE: while (defined($_ = ARGV)) {
 chomp $_;
 s/n/t/;
 s///g;
 }
 continue {
 print $_;
 }
 -e syntax OK

 which shows a little confusion over $/ and $, and an unnecessary  in the
 initial program.

  This taught me a lot.

 Good :-)

Thanks for your help guys...

But the code is performing the logic only for the first set of lines...

After the running the above script, the output looks like

Object1...tab...Description1

Object2
Description2

Object3
Description3






-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: how do i describe a perl user?

2004-09-30 Thread Sano Babu
On Thu, 30 Sep 2004 11:35:24 -0500, Errin Larsen [EMAIL PROTECTED] wrote:
 
 
 On Fri, 1 Oct 2004 01:37:44 +0930, Sano Babu [EMAIL PROTECTED] wrote:
  just wondering what a user of Perl may be called? Perler?? Theres
  got to be some fancy name for it. Perl is not just another programming
  language.. I reckon its much more like a religion with attitude.. :)
 
  Cheers,
  SanoBabu
 
 
 I say 'Perler' when I'm addressing this list.  Haven't had anyone
 complain yet!  I haven't seen anything else!  Anyone else have some
 suggestions?  The 'Guru's on the web are at a site called Perl
 Monks.  But what do you call a devotee, not a guru?

Well thats what http://www.google.com/search?q=define%3A%20guru says..
i say to be a guru someone has to be nutcrack... :) It takes a lot of
patience, hardship to be one.. lets say like Randal, Larry or Tom who
help peps with that same answer over n over again..
I read somewhere Perl monks are like maniacs or something.. :) but in
a good way.. All Perl hacker are maniacs i guess with coffeine
ejecting out of their nerves..
As i say this i am still learning Perl and intend to be like them one
day...(lets see when that day is now [ nodding to myself ] )

 --Errin
 


-- 
Cheers,
SanoBabu

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help with script

2004-09-30 Thread Paul Johnson
On Thu, Sep 30, 2004 at 11:26:27AM -0500, Errin Larsen wrote:

 When I run your command line up there, I get the following:
 
 # perl -MO=Deparse -l00pe's/\n/\t/;s/\//g'
 LINE: while (defined($_ = ARGV)) {
 chomp $_;
 s/\n/\t/;
 s///g;
 }
 continue {
 print $_;
 }
 -e syntax OK
 
 What OS are you running?  My '-MO=Deparse' didn't create that BEGIN
 Block.  I'm on Solaris, using Perl 5.6.1.  I'm just curious what the
 difference is.

That was on linux, but the important thing here is the perl version.
5.6.1 is old, and if you are looking at the B modules (which Deparse is)
it's very old.  There have been many improvements (bug fixes) since
then.

 --Errin
 
 BTW, I didn't know about the Deparse Pre-Compiler thing!  Thanks for
 pointing it out.  It's very handy.  Why do you think Perl uses:
 
   while( defined( $_ = ARGV ) )
 
 instead of:
   
   while(  )
 
 Is this example pointing out that the diamond (  ) operator is
 really a short-cut for 'defined( $_ = ARGV )' ?

Yes, exactly that.

I'll have to go
 read about this.  What is Perl protecting against by putting that
 assignment in a defined()?

It's protecting against input which evaluates to false, such as the last
line of a file which contains only 0 and no newline, for example.

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




How to accumulate Hashes of Array value with the same key?

2004-09-30 Thread Edward Wijaya
Hi,
I have thre HoAs with the same key but different value.
How can I efficiently join the HoA:
my %HoA = (key1 = ['A',1]);
my %HoA2 = (key1 = ['B',2]);
my %HoA3 = (key1 = ['C',2]);
into:
%HoA = (key1 = ['A',1],['B',2],['C',2]);
namely accumulating the value of HoA2,HoA3 into  HoA.
Thanks very much for the time.
Regards,
Edward WIJAYA
SINGAPORE
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: How Can I rename File using Perl?..

2004-09-30 Thread Gavin Henry
 Moreover, rename() is a basic part of Perl, so even on Linux there is no
 need to do this with a system call to the `mv` command.

Of course, doh.

-- 
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-09-30 Thread Gavin Henry
On Thursday 30 Sep 2004 13:19, Randal L. Schwartz wrote:
  John == John W Krahn [EMAIL PROTECTED] writes:

 John You might hurt his feelings, he didn't contribute to the third
 edition John of Programming Perl.

 Actually, it's worse than that.  I contributed to it, but wasn't credited
 for it or paid for it.

Can you reveal anymore about this, as I read it on stonehenge too.


 John   Better to buy his latest book _Learning Perl
 John Objects, References  Modules_  ;-)

 Yes, or Learning Perl.  Both good books, from what I hear.  I dunno,
 I write'em, not read 'em. :)

Ha, this is great.


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

-- 
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-09-30 Thread Sano Babu
 Can you reveal anymore about this, as I read it on stonehenge too.

  Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
  [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/
  Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.

 Does Randal write Comedy  stuff as well? It would be a best seller
 amongst Perl Programmers I gues.. :)
 
  See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl
  training!
 



-- 
Cheers,
SanoBabu

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: How to accumulate Hashes of Array value with the same key?

2004-09-30 Thread Shaw, Matthew
 I have thre HoAs with the same key but different value.
 How can I efficiently join the HoA:
 
 my %HoA = (key1 = ['A',1]);
 my %HoA2 = (key1 = ['B',2]);
 my %HoA3 = (key1 = ['C',2]);
 
 into:
 
 %HoA = (key1 = ['A',1],['B',2],['C',2]);
 

push @{$HoA{key1}}, ( @{$HoA2{key1}}, @{$HoA2{key1}});

 --
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




RE: Regex:: using variables to hold replacement text

2004-09-30 Thread William Lewis Brown
On Thu, 2004-09-30 at 10:58, Bob Showalter wrote:
 William Lewis Brown wrote:
  Hi,
  I have a need to store replacement text for a regex
  substitution in a variable.  In other words, I have code in a perl
  script like so:: 
  
  $foo =~ s/(.*)bar(.*)/$replacement/g;
  
  The $replacement string needs to contain a reference to $1.  In
  other words, the string $replacement will contain the string $1.  I
  need to have the $1 string interpreted so that it will be replaced
  with the text of the first '(.*)' expression.  I have not yet found a
  way to get this to happen.  The $1 string always seems to be
  interpreted as a plain string.
 
 You need to use eval and /e
 
 $foo =~ s/(.*)bar(.*)/eval $replacement/ge;

Hi,
That definitely did the trick.  I had tried eval and /e but never
in conjunction.  Thanks for your time and your help.

Bill

-- 
William L. Brown
Email: [EMAIL PROTECTED]


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help with script

2004-09-30 Thread Errin Larsen
 Thanks for your help guys...
 
 But the code is performing the logic only for the first set of lines...
 
 After the running the above script, the output looks like
 
 Object1...tab...Description1
 
 Object2
 Description2
 
 Object3
 Description3

Can you post EXACTLY what's in the input file for us?

I test with the following input file, I called it object.txt:
# cat object.txt
Object1
Description1

Object2
Description2

Object3
Description3

I run this command line:
# perl -l -00pe's/\n/\t/;s/\//g' object.txt
Object1 Description1
Object2 Description2
Object3 Description3

It's hard to see the tabs, so I tried one with 2 tabs in it for clarity:
# perl -l -00pe's/\n/\t\t/;s/\//g' object.txt
Object1 Description1
Object2 Description2
Object3 Description3

So, on my (Solaris 9, Perl 5.6.1) box, it's working.  What OS and Perl
version are you using and what's your input file look like?

--Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




difference between @_ and shift

2004-09-30 Thread Graeme McLaren
Hi all, I'm having a look in to object oriented perl.  Can anyone tell me 
what the difference between @_ and shift is?  As far as I know there is no 
difference except shift removes the parameter from the @_ array so if you 
were to shift all parameters passed to a function nothing would be 
containted in @_   is this correct?

I'm asking because I'm a little confused about using it.  Why can't I do 
this:

###
sub nickname {
   my $self = shift;
   return $self-{NICK};
}
###
But I can do this:
###
sub nickname {
   my $self = shift;
if (@_) { $self-{NICK} = shift
}
   return $self-{NICK};
   }
###
_
Express yourself with cool new emoticons http://www.msn.co.uk/specials/myemo
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: difference between @_ and shift

2004-09-30 Thread Wiggins d Anconia
 Hi all, I'm having a look in to object oriented perl.  Can anyone tell me 
 what the difference between @_ and shift is?  

One is a variable, one is function/operator ;-)

As far as I know there is no 
 difference except shift removes the parameter from the @_ array so
if you 
 were to shift all parameters passed to a function nothing would be 
 containted in @_   is this correct?
 

@_ is just a special Perl variable, it so happens that it is what is
used to store the arguments to a subroutine temporarily (it has other
uses, see perldoc perlvar).  It also happens that the first argument to
a subroutine acting like a method is always the object/class that the
method is invoked on. Cshift is just a function that removes the
first/top element of an array, any array, in OOP or not. 

This happens to make things very convenient, aka in most methods you
will want to remove the instance/class from the argument list to get the
 actual argument list back, and shift by itself will default to use @_.
So essentially you are left with some syntactic sugar to make life easier.

So,

my $self = shift;

Just says to grab the instance from @_ (by default), store it in $self,
and restore the arg list to what the user actually passed.  You don't
*have* to do it, but it is very convenient.

 I'm asking because I'm a little confused about using it.  Why can't I do 
 this:
 
 ###
 sub nickname {
 my $self = shift;
 return $self-{NICK};
 }

No reason you can't.  Provided you have already set $self-{NICK} or
don't mind getting an undefined value. 


 ###
 
 But I can do this:
 
 ###
 sub nickname {
 my $self = shift;
   if (@_) { $self-{NICK} = shift
   }
 return $self-{NICK};
 }
 ###
 

Only difference here is that you set $self-{NICK} in the event that an
argument was passed, aka after shift'ing there is still an argument in
@_ (namely the value you want to set NICK to).

Additional suggested reading:

perldoc perlboot
perldoc perltoot
perldoc perltooc

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Errin Larsen
I am (admitedly) unfamiliar with OO Perl.  I understand enough to grok
what you are saying, Wiggins, but I have a question.

Does a sub (like the one above) have a problem with being called with
 as opposed to not being called with an  with OO Perl?  That
questions was worded weird.  Let me try again.  As I understand it, if
you call a sub with 'subname', the sub's @_ variable will share the
calling scope's @_ variable, BUT, if you call the sub with 'subname()'
it will get it's own, fresh @_.  is that true?  And if it is, does
this affect the subs being used with OO Perl?

--Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Chris Devers
On Thu, 30 Sep 2004, Graeme McLaren wrote:

  Can anyone tell me what the difference between @_ and shift is?

The former is a variable; the latter is a function. 

@_ is one of Perl's pronoun variables: just as $_ refers to that 
which you were most recently working with, @_ refers to those which 
you were most recently working with. $_ is a scalar -- it or that; a 
single thing. @_ is a list -- those or these; a plural thing.

shift is a function for pulling off the first element from a list. If 
you've ever had to take a data structures class, you may remember that 
two of the main ways to deal with collections of things as as stacks 
(where you only deal with the top, and you can push onto it or pop off 
of it) and queues (where everything moves in a line, and you enqueue 
onto the end and dequeue from the front). Perl has functions that let 
you work with arrays in these ways. You can push to and pop from the end 
of lists to treat them as stacks; you can shift from and unshift to the 
front of lists to, well, also treat them as stacks; and you can push  
shift or pop  unshift to treat it as forward or reverse queues. 

So. In the context of subroutine arguments, you're generally passing in 
one or more arguments. If you're only passing one, then you're right --

   my $arg = @_;
   my $arg = shift;
   my $arg = $_;

-- are all equivalent. If, on the other hand, you have multiple args, 
then these will all do different things. 

   my @args = @_;

   my $arg[0] = shift;
   my $arg[0] = $_;

If you pass the wrong thing and aren't ready for it, you can throw away 
incoming data and possibly break things. 

 As far as I know there is no difference except shift removes the 
 parameter from the @_ array so if you were to shift all parameters 
 passed to a function nothing would be containted in @_ is this 
 correct?

Well, yes, in that this will deplete @_, but that doesn't mean that 
there is no difference between shift and @_ -- they're different things.
 


-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Check for valid email address

2004-09-30 Thread Denzil Kruse
Hi all,
 
I have a bunch of old email addresses in a database and would like to make sure they 
are deliverable before I try to send anything to them.  I don't need to find each and 
every bad one, just find most of them.  Or at least reduce the undeliverables to a 
more managable level.
 
I read through perlfaq9 and the Mail and Email modules.  It sounds like Mail::EXPN and 
Mail::SPF::Query depends upon the sender's host to make information available, which 
I'm assuming few do.  Mail::Verify and Mail::CheckUser seem pretty much the same and 
sound like the best option so far.  I haven't looked close at Email:Valid but if it's 
based upon Net stuff then it's tcp/ip based?  Don't want that, I don't think.
 
I'm just a little confused by all of the options above, and don't have any experience 
to see how well they actually work.  Does anyone have any ideas or just point me in 
the right direction?  I'm pretty new to the email world.
 
Thanks,
Denzil


-
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!

Re: difference between @_ and shift

2004-09-30 Thread Sano Babu
On Thu, 30 Sep 2004 20:19:11 +0100, Graeme McLaren
[EMAIL PROTECTED] wrote:
 Hi all, I'm having a look in to object oriented perl.  Can anyone tell me
 what the difference between @_ and shift is?  As far as I know there is no

Straight from the Llama :
@array = qw /dino fred barney/;
$a = $shift @array; # $a gets dino, @array reduced to (fred , barney);

 difference except shift removes the parameter from the @_ array so if you
 were to shift all parameters passed to a function nothing would be
 containted in @_   is this correct?

@_ variable is local to the subroutine. It stores argument to a
subroutine. If u keep on doing shift inside a subroutine then @_
will be empty  will become uninitialized again.
  sub test {
  #$a = shift ;
  my $a = shift @_ ;
  print $a;
  my $b = shift @_;
  print $b;
  }
test(1);
-perl -w test.pl
-Use of uninitialized value in print at test.pl line 9.
1

But this doesn't in anyway affect the @_ variable outside the
subroutine if there happens to be any.

 I'm asking because I'm a little confused about using it.  Why can't I do
 this:

 ###
 sub nickname {
my $self = shift;
return $self-{NICK};
 }
 ###

[snip]

$self looks alot like this in Java.. no? :)

-- 
Cheers,
SanoBabu

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Wiggins d Anconia
 I am (admitedly) unfamiliar with OO Perl.  I understand enough to grok
 what you are saying, Wiggins, but I have a question.
 
 Does a sub (like the one above) have a problem with being called with
  as opposed to not being called with an  with OO Perl?  That
 questions was worded weird.  Let me try again.  As I understand it, if
 you call a sub with 'subname', the sub's @_ variable will share the
 calling scope's @_ variable, BUT, if you call the sub with 'subname()'
 it will get it's own, fresh @_.  is that true?  And if it is, does
 this affect the subs being used with OO Perl?
 
 --Errin

Solid question, which took some hunting in the docs but they are
solid docs, from perldoc perltoot, 

From the C++ perspective, all methods in Perl are virtual.  This, by
the way, is why they are never checked for function prototypes in the
argument list as regular builtin and user-defined functions can be.

This confirmed my hunch.  The C has a number of purposes beyond just
passing the current @_ in recursive like functions, such as
dereferencing subroutines, etc.   See perldoc perlsub for lots about
subroutines, prototypes, and their behaviours.  My hunch was that since
you invoke a method on an object/class, such as

My::Class-method();
or 
$object-method();

You would have to figure out where to put the sigil, 

$object-method();

Would either cause confusion wrt trying to dereference a subroutine, or
trying to chain a method on the return value of a dereferenced
subroutine, which would be pretty cool, though not terribly readable. Or,

$object-method();

Which I suspected could work, but had never seen it before (not that I
am an expert) but it strikes me as something difficult to parse.

Now to the more important part, and the more literal meaning of your
question, in Perl it doesn't affect anything!  Why? because the method,
when invoked as a regular sub call will run just fine!  The danger is
that you (may) have broken the interface, so if the sub is really a
method *expecting* the first argument to be an object/class, then it may
fail to function as documented. This is where the beauty of Perl comes
in though, why can't you have both!  For instance many subs can check
their first argument to see if it is a reference, in that case it treats
the call like a method, if the first arg isn't, then it treats it like a
regular sub call.  This is similar to other areas of Perl that function
based on the *context*.  Many modules that provide a functional and OOP
interface are operating under this principal.  So whether or not Perl
will let you, it will, whether or not you can/should depends on the
underlying implementation and whether it is documented.  Calling what is
normally a method with C as a regular sub call will pass @_
unmangled, the question becomes does @_ already have the object/class
attached, or is the sub smart enough to recognize that it doesn't.

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Wiggins d Anconia
 On Thu, 30 Sep 2004, Graeme McLaren wrote:
 
   Can anyone tell me what the difference between @_ and shift is?
 

snip

 So. In the context of subroutine arguments, you're generally passing in 
 one or more arguments. If you're only passing one, then you're right --
 
my $arg = @_;

DANGER, DANGER the above takes a list in scalar context, $arg is now
'1', not the value of the first argument.  Throw in some parens to fix
that guy

my ($arg) = @_;

my $arg = shift;
my $arg = $_;
 
 -- are all equivalent. If, on the other hand, you have multiple args, 
 then these will all do different things. 
 

snip

 
 -- 
 Chris Devers
 

http://danconia.org

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Sano Babu
  So. In the context of subroutine arguments, you're generally passing in
  one or more arguments. If you're only passing one, then you're right --

  my $arg = @_;
So what wiggins saying, here $arg has now 1 ? 

  my $arg = shift;
here $arg has now the value of the first element(argument) ? 

  my $arg = $_;
here $arg gets default value?

   -- are all equivalent.

I agree. :)

[snip]
-- 
Cheers,
SanoBabu

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Wiggins d Anconia
   So. In the context of subroutine arguments, you're generally passing in
   one or more arguments. If you're only passing one, then you're right --
 
   my $arg = @_;
 So what wiggins saying, here $arg has now 1 ? 


Yes. It is the length of the array, or a list taken in scalar context.
 
   my $arg = shift;
 here $arg has now the value of the first element(argument) ? 
 
   my $arg = $_;
 here $arg gets default value?

Ha, didn't even notice that one, yep $_ is definitely different than
$_[0], which is what the others would have. 

 
-- are all equivalent.
 
 I agree. :)
 

?? You are agreeing that they are, or aren't?  They definitely aren't.

 [snip]
 -- 
 Cheers,
 SanoBabu
 

http://danconia.org


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Sano Babu
 Ha, didn't even notice that one, yep $_ is definitely different than
 $_[0], which is what the others would have.
 
 
 -- are all equivalent.
 
  I agree. :)
 
 
 ?? You are agreeing that they are, or aren't?  They definitely aren't.

hahah..That was a bad post..I mean I agree with what u said. :-) 

 
[snip]

-- 
Cheers,
SanoBabu

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Configuration File

2004-09-30 Thread Errin Larsen
Hi Perlers,

I'm trying to implement one of the recipes I found in the Perl
Cookbook.  It is 8.16. Reading Configuration Files recipe.  Here are
some snippets from that text:

  ... Or better yet, treat the config file as full Perl code:

do $ENV{HOME}/.progrc;
...
The second solution uses do to pull in raw Perl code directly. When
used with an expression instead of a block, do interprets the
expression as a filename. This is nearly identical to using require,
but without risk of taking a fatal exception.
...
You might wonder what context those files will be executed under. They
will be in the same package that do itself was compiled into.
Typically you'll direct users to set particular variables, which,
being unqualified globals, will end up in the current package. If
you'd prefer unqualified variables go into a particular package, do
this:

{ package Settings; do $ENV{HOME}/.myprogrc }

As with a file read in using require or use, those read in using do
count as a separate and unrelated lexical scope. That means the
configuration file can't access its caller's lexical (my) variables,
nor can the caller find any such variables that might have been set in
the file. It also means that the user's code isn't held accountable to
a pragma like use strict or use integer that may be in effect in the
caller.


My code looks like this (for testing):

  #!/usr/bin/perl
  # configtest.pl

  use warnings;
  use strict;

  { package Config; do configtest.conf }

  print $_\n for( @Config::FILE_NAME );

My configtest.conf file looks like this:
  
  # A list of file names
  @FILE_NAME = qw[
/This/is/a/test
/This/is/also/a/test
/And/this/is/the/last/test
  ];

Now, this code runs, and produces the expected output.  However, it
also gives me a warning:
  Name Config::FILE_NAME used only once: possible typo at
./configtest.pl line 7.

I realize I can just turn my pragmas off after testing/implementation
to get rid of this, but is there a better way?  Perhaps my Perl
Cookbook is just old (yup, 1st edition.  Has this recipe been
updated?)

--Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: How to accumulate Hashes of Array value with the same key?

2004-09-30 Thread Dave Gray
 I have thre HoAs with the same key but different value.
 How can I efficiently join the HoA:
 
 my %HoA = (key1 = ['A',1]);
 my %HoA2 = (key1 = ['B',2]);
 my %HoA3 = (key1 = ['C',2]);
 
 into:
 
 %HoA = (key1 = ['A',1],['B',2],['C',2]);

I'm not sure what you want to do here... do you want to combine all
the values into one array reference, stored in $HoA{key1}? Or do you
want $HoA{key1} to be an array of arrays?

Another solution might be to use a hash of hashes:

%HoA = (
  key1 = {
A = 1,
B = 2,
C = 3
  }
);

This sounds like it's part of a bigger question. Can you give us some
more background info?

Dave

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Check for valid email address

2004-09-30 Thread Gunnar Hjalmarsson
Denzil Kruse wrote:
I have a bunch of old email addresses in a database and would like
to make sure they are deliverable before I try to send anything to
them.
snip
Does anyone have any ideas or just point me in the right direction?
I'd say: Forget it. You can't find out whether an email address is
deliverable without asking the mail server of that address, i.e.
trying to send a message. What you can do is testing if the
domain/host has an MX record. And you can of course test the syntax,
but that's it.
Why don't you just send a message and ask the recipients to confirm
that they are still reading their messages to respective address?
Because you are not going to send any unsolicited crap anyway, right?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Need help with script

2004-09-30 Thread PerlDiscuss - Perl Newsgroups and mailing lists
I am using Cygwin on Win2K and the version of perl on it is 
v5.8.0

I am using the same input file, but when I run the command you ran, the
output looks like

Object1  Description1

Object2
Description2

Object3
Description3

Thanks


Errin Larsen wrote:

  Thanks for your help guys...
  
  But the code is performing the logic only for the first set of lines...
  
  After the running the above script, the output looks like
  
  Object1...tab...Description1
  
  Object2
  Description2
  
  Object3
  Description3

 Can you post EXACTLY what's in the input file for us?

 I test with the following input file, I called it object.txt:
 # cat object.txt
 Object1
 Description1

 Object2
 Description2

 Object3
 Description3

 I run this command line:
 # perl -l -00pe's/n/t/;s///g' object.txt
 Object1 Description1
 Object2 Description2
 Object3 Description3

 It's hard to see the tabs, so I tried one with 2 tabs in it for clarity:
 # perl -l -00pe's/n/tt/;s///g' object.txt
 Object1 Description1
 Object2 Description2
 Object3 Description3

 So, on my (Solaris 9, Perl 5.6.1) box, it's working.  What OS and Perl
 version are you using and what's your input file look like?

 --Errin



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Configuration File

2004-09-30 Thread Gunnar Hjalmarsson
Errin Larsen wrote:
  { package Config; do configtest.conf }
  print $_\n for( @Config::FILE_NAME );
snip
Now, this code runs, and produces the expected output.  However, it
also gives me a warning:
  Name Config::FILE_NAME used only once: possible typo at
./configtest.pl line 7.
I realize I can just turn my pragmas off after testing/implementation
to get rid of this, but is there a better way?
Nothing prevents you from declaring @FILE_NAME:
package Config;
our @FILE_NAME;
do configtest.conf;
print $_\n for @FILE_NAME;
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Check for valid email address

2004-09-30 Thread Denzil Kruse


Gunnar Hjalmarsson [EMAIL PROTECTED] wrote:

I'd say: Forget it. You can't find out whether 
an email address is deliverable without asking
the mail server of that address, i.e.
trying to send a message. What you can do is 
testing if the domain/host has an MX record. 
And you can of course test the syntax, but 
that's it.

Okay, that sounds like Mail::Verify then.

Why don't you just send a message and ask the
recipients to confirm that they are still reading
their messages to respective address?

That's what we started doing, and about 60% of them
are undeliverable.

Because you are not going to send any unsolicited
crap anyway, right?

No, it's an old program that has been in limbo for a
while and we wanted to contact the people that are
still signed up and let them know it is out of limbo.

Thanks for the help, I'll probabaly give the Verify a
try then.

Denzil











__
Do you Yahoo!?
Yahoo! Mail - 50x more storage than other providers!
http://promotions.yahoo.com/new_mail

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Check for valid email address

2004-09-30 Thread Gunnar Hjalmarsson
Denzil Kruse wrote:
Gunnar Hjalmarsson wrote:
What you can do is testing if the domain/host has an MX record.
And you can of course test the syntax, but that's it.
Okay, that sounds like Mail::Verify then.
I had a look at the source of Mail::Verify, and even if the module
claims to verify the syntax, it doesn't really. You may want to check
out e.g. Email::Valid, too.
Or: This is a function I'm using in a couple of programs to check the
syntax, and that I believe is sufficient in practice:
sub emailsyntax {
return 1 unless
  my ($localpart, $domain) = shift =~ /^(.+)@(.+)/;
my $char = '[^()@,;:\/\s\'|.]';
return 1 unless $localpart =~ /^$char+(?:\.$char+)*$/ or
  $localpart =~ /^[^,]+$/;
$domain =~ /^$char+(?:\.$char+)+$/ ? 0 : 1;
}
OTOH, since you know that the addresses were valid once, the syntax
check may not be your first priority.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Need help with script

2004-09-30 Thread Errin Larsen
On 30 Sep 2004 19:52:31 -, PerlDiscuss - Perl Newsgroups and
mailing lists [EMAIL PROTECTED] wrote:
 I am using Cygwin on Win2K and the version of perl on it is
 v5.8.0
 
 I am using the same input file, but when I run the command you ran, the
 output looks like
 
 Object1  Description1
 
 Object2
 Description2
 
 Object3
 Description3
 
 Thanks
 


Hi again,

Just to let you know, most on this list will become upset with you if
you don't bottom-post.  For future reference ...


Ok, I've got ActiveState on WinXP, 5.8.4 ... I tried and found that I
had the same problems as you.  After much playing around, I found it's
a quoting problem on the command line (at least, in my case it was). 
I just don't have a good grasp of quoting rules and precedence in DOS
I guess.  Here's what I did to make it work on my DOS command line:

C:\  perl -l -00pe s/\n/\t/;s/\//g object.txt

I basically just removed the single-quotes from around the code in the
'-e' option.  That gave me the output I was looking for.  Try it and
let us know.

--Errin

BTW, anyone have a good reference for DOS quoting rules/precedence?

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Configuration File

2004-09-30 Thread Errin Larsen
On Thu, 30 Sep 2004 23:30:16 +0200, Gunnar Hjalmarsson
[EMAIL PROTECTED] wrote:
 
 Nothing prevents you from declaring @FILE_NAME:
 
  package Config;
  our @FILE_NAME;
  do configtest.conf;
  print $_\n for @FILE_NAME;
 
 --
 Gunnar Hjalmarsson
 Email: http://www.gunnar.cc/cgi-bin/contact.pl

doesn't that kinda defeat the purpose of declaring the Config name
space?  I was trying to keep the variables in the configtest.conf file
in a different name space than the main program.  I don't HAVE to do
this, just thought it seemed like a good way to keep the two,
potentially conflicted, name spaces apart.  I wanted to see the
variables created in the Config name space require a dereference (is
that the right word?), ala Config::FILE_NAME.  That way, if the main
code ALSO has a FILE_NAME variable, the contents of the (at run time,
unknown to the main developer) config file.

I hope that's making sense.

--Errin

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Check for valid email address

2004-09-30 Thread Sano Babu
On Thu, 30 Sep 2004 23:58:34 +0200, Gunnar Hjalmarsson
[EMAIL PROTECTED] wrote:
 Denzil Kruse wrote:
  Gunnar Hjalmarsson wrote:
  What you can do is testing if the domain/host has an MX record.
  And you can of course test the syntax, but that's it.
 
  Okay, that sounds like Mail::Verify then.
 
 I had a look at the source of Mail::Verify, and even if the module
 claims to verify the syntax, it doesn't really. You may want to check
 out e.g. Email::Valid, too.

Gunnar let me ask u a question.. :) DO u ever sleep?? U're constantly
helping people out here... It seems u never step back from helping :)
anyway thats good. and personally i've not had a chance to ask u
questions in Perl in this list as i am still pretty much a learner,
let me take a break n say thanks :-) (OK thats not much or is it?)..
Its really nice to have people around for support while learning. :-)

[snip]
 
 
 --
 Gunnar Hjalmarsson
 Email: http://www.gunnar.cc/cgi-bin/contact.pl
 
[snip]

-- 
Cheers,
SanoBabu

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Configuration File

2004-09-30 Thread Gunnar Hjalmarsson
Errin Larsen wrote:
Gunnar Hjalmarsson wrote:
Nothing prevents you from declaring @FILE_NAME:
package Config;
our @FILE_NAME;
do configtest.conf;
print $_\n for @FILE_NAME;
doesn't that kinda defeat the purpose of declaring the Config name
space?
Can't see how. It is being declared within package Config.
I was trying to keep the variables in the configtest.conf file in a
different name space than the main program.
That sounds wise, and I didn't suggest anything else.
I wanted to see the variables created in the Config name space
require a dereference (is that the right word?),
No. You mean require the fully qualified names.
ala Config::FILE_NAME.
If you don't export anything from package Config, you still need to
use the fully qualified names when calling those variables from other
packages, so I don't think that's a reason either to not declare the
variables in package Config.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Check for valid email address

2004-09-30 Thread Gunnar Hjalmarsson
Sano Babu wrote:
Gunnar let me ask u a question.. :) DO u ever sleep??
Yeah, it happens. :)
U're constantly helping people out here... It seems u never step
back from helping :)
Well, I'm not alone, right? Actually, there are people for whom that
is more true than it is for me, and who have been around much longer
than me.
anyway thats good. and personally i've not had a chance to ask u
questions in Perl in this list as i am still pretty much a learner,
let me take a break n say thanks :-)
You're welcome. And let that be a thanks to everyone who are answering
questions here.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Need help with script

2004-09-30 Thread PerlDiscuss - Perl Newsgroups and mailing lists
 Hi again,

 Ok, I've got ActiveState on WinXP, 5.8.4 ... I tried and found that I
 had the same problems as you.  After much playing around, I found it's
 a quoting problem on the command line (at least, in my case it was). 
 I just don't have a good grasp of quoting rules and precedence in DOS
 I guess.  Here's what I did to make it work on my DOS command line:

 C:  perl -l -00pe s/n/t/;s///g object.txt

 I basically just removed the single-quotes from around the code in the
 '-e' option.  That gave me the output I was looking for.  Try it and
 let us know.

 --Errin

 BTW, anyone have a good reference for DOS quoting rules/precedence?

If I remove single quotes, my command kind of hangs..it does not give any
output.

thanks



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Need help with script

2004-09-30 Thread John W. Krahn
Errin Larsen wrote:
Hi Perlers,
On 30 Sep 2004 10:11:29 +0100, Jose Alves de Castro
[EMAIL PROTECTED] wrote:
On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote:
I would like the output in the following format
object1...tabDescription1
object2...tabDescription2
object3...tabDescription3
perl -lne 'BEGIN{$/=\n\n;}s/\n/\t/;print' FILENAME
perl -l -00pe's/\n/\t/' FILENAME
That's pretty slick you guys, he's sure to get an A+ ;)
If your teacher requires the quotes to be removed:
What if the teacher requires an explanation? O:-)
It is my opinion that code should be explained, at least in this list.
You're trying to teach people how to fish (and maybe swim). Giving them
fish is good, of course, but tell them how you got it :-)
That said, nice code :-)
 perl -l -00pe's/\n/\t/;s/\//g;' FILENAME
I'll give it a try.
First, it's good to know that the two Perl special variables '$/' and
'$\' are the input separator and output separator.  By Default, they
will be $/ = \n (newline character) and $\ = undef (nothing.  No
output separator).
So far so good.  :-)
Now, on the command line, the '-0' option will set the input separator
($/).  In the above example, it's setting $/ = 0.
Wrong.
Also, in the
example, the '-l' will do two things.  First, it will automatically
chomp() whatever's in '$/', and then it will set the output separator
to be whatever the input separator will be.  So, specific to our
example, first '-l' sets '$\' (output separator) to whatever '$/' is
(at this point, it's \n, or a newline).  Then, the '-0' switch is
setting the $/ = 0 ( or null, or nothing!).
perldoc perlrun
[snip]
  -0[octal/hexadecimal]
   specifies the input record separator ($/) as an octal or hexadecimal
   number.  If there are no digits, the null character is the separator.
^^^
   Other switches may precede or follow the digits.  For example, if you
   have a version of find which can print filenames terminated by the null
   character, you can say this:
   find . -name '*.orig' -print0 | perl -n0e unlink
   The special value 00 will cause Perl to slurp files in paragraph mode.
   ^
   The value 0777 will cause Perl to slurp files whole because there is no
   legal byte with that value.
So using the switch -00 is the same as setting the input record separator to 
paragraph mode or $/ = '';


John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Need help with script

2004-09-30 Thread John W. Krahn
Paul Johnson wrote:

On Wed, 2004-09-29 at 21:25, JupiterHost.Net wrote:
 perl -l -00pe's/\n/\t/;s/\//g;' FILENAME
$ perl -MO=Deparse -l00pe's/\n/\t/;s/\//g'
BEGIN { $/ = \n; $\ = \000; }
In your example you have removed the -0 switch so it is doing something 
completely different.

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: printing block of text

2004-09-30 Thread John W. Krahn
Murphy, Ged (Bolton) wrote:
I'm trying to print a block of code using 'print LABEL; but am getting an
error stating perl can't find the termination label.
Test code and error as follows:
#!/usr/bin/perl
print TEST;
this is my tester text
TEST
Can't find string terminator TEST anywhere before EOF at photo.pl line 3.
Anyone got any ideas as to why it's doing this?
perl is looking for a string terminator that looks like \nTEST\n.  Your 
editor may not be putting a newline at the end of the file.  Try putting an 
extra one or two blank lines after the terminator.

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: Check for valid email address

2004-09-30 Thread Denzil Kruse

--- Gunnar Hjalmarsson [EMAIL PROTECTED] wrote:

 I had a look at the source of Mail::Verify, and even
 if the module
 claims to verify the syntax, it doesn't really. You
 may want to check
 out e.g. Email::Valid, too.

I already know the email is works because we've sent
them before, so I'll just use the Verify.  That's good
to know that I need to check the address with another
function.   I wouldn't have looked at the internals of
the module.

Thanks for your help!

And BTW, I usually snip most of the history of the
email threads just to keep it clean.  I don't know
what the etiquette is on this list.  Do people like to
see the whole conversation?

Denzil



__
Do you Yahoo!?
New and Improved Yahoo! Mail - Send 10MB messages!
http://promotions.yahoo.com/new_mail 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




sum a column

2004-09-30 Thread rmck
Hello,
 
Im trying to sum up a column from my results. Help.
 
current output:
Date_Time, SRCIP, DSTIP, TOTALBYTES
01-01-2004 12:56:48, 192.168.1.1, 192.168.2.2, 2768
Sum Of Bytes = 2768
01-01-2004 12:56:48, 192.168.2.2, 192.168.1.1, 438
Sum Of Bytes = 876
01-02-2004 16:49:45, 192.168.3.3, 192.168.4.4, 9058
Sum Of Bytes = 27174
01-02-2004 16:49:45, 192.168.4.4, 192.168.3.3, 918
Sum Of Bytes = 3672
 
goal:
Date_Time, SRCIP, DSTIP, TOTALBYTES
01-01-2004 12:56:48, 192.168.1.1, 192.168.2.2, 2768
01-01-2004 12:56:48, 192.168.2.2, 192.168.1.1, 438
Sum Of Bytes = 3206
01-02-2004 16:49:45, 192.168.3.3, 192.168.4.4, 364
01-02-2004 16:49:45, 192.168.4.4, 192.168.3.3, 513
Sum Of Bytes = 877
 
 
Im stuck. Should I use a hash??
 
Current Script:
#!/usr/bin/perl
use Socket;
use strict;
use POSIX 'strftime';
use warnings;
my $time = strftime %y%m%d%H, localtime;
my $count = 0;
 
# open the file
open(LOG,@ARGV) or die Unable to open LOG:$!\n;

print Date_Time, SRCIP, DSTIP, TOTALBYTES \n;

# read it in one record at a time
while (LOG) {
my ($logdate,$srcip,$dstip,$totalbytes) = split(/\t/,$_);
my ($date,$time )= split(/\s/,$logdate);
my @hour = split(/:/,$time);
 
next if $_ =~ /^\D/;

if ($hour[0] = 6 and $hour[0]  22){
print  $logdate,$srcip,$dstip,$totalbytes;
$count++;
my $sum = $count * $totalbytes;
print Sum of Bytes = $sum\n;
  }
   }
# close the file
close(LOG);

 
Thanks for any input..
 
Rob
 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: Check for valid email address

2004-09-30 Thread Gunnar Hjalmarsson
Denzil Kruse wrote:
I usually snip most of the history of the email threads just to
keep it clean.
Sounds as common sense to me, and it's probably part of the general
'netiquette' to only quote what's needed to give context.
I don't know what the etiquette is on this list.  Do people like to
see the whole conversation?
I for one agree with you.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: sum a column

2004-09-30 Thread Gunnar Hjalmarsson
Rmck wrote:
Im trying to sum up a column from my results. Help.
job specification snipped
Im stuck.
I don't believe you. To be stuck, you need to try first, and I suspect 
that you didn't do that. Note that this is not a free service for 
modifying scripts that people pick up somewhere.

I suggest that you make a serious attempt to solve the 'problem', and 
come back here if you encounter problems.

If you don't know any Perl at all, start here:
http://learn.perl.org/
or hire a consultant to help you.
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: difference between @_ and shift

2004-09-30 Thread John W. Krahn
Chris Devers wrote:
The former is a variable; the latter is a function. 

@_ is one of Perl's pronoun variables: just as $_ refers to that 
which you were most recently working with, @_ refers to those which 
you were most recently working with. $_ is a scalar -- it or that; a 
single thing. @_ is a list -- those or these; a plural thing.

shift is a function for pulling off the first element from a list.
Wrong!  If you try to use shift() with a list it will print out a nice error 
message Type of arg 1 to shift must be array.

perldoc -q What is the difference between a list and an array
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Help with Archive::Zip

2004-09-30 Thread dennis . gray




I have had limited success with using this package but do need some help.

Here is my problem:
   I have a directory containing thousands of .zip files, each with a
   single text file.
   The archive files have the name in the format IMBFILE.zip, where
    is a sequence number.
   The each text file in the archive file has the same name
   requestString. The text file is XML

Here is a snippet of the code the creates the archive file by extracting a
blob from an Oracle database (this part works)

while (@row = $sth-fetchrow_array)
{
  if (defined $row[1]) {
$filename = request_response/\IMBFILE . $row[0] . .zip;
open IMB,$filename;
binmode IMB;
print IMB $row[1];
$imbcount++;
  }

  if (defined $row[2]) {
$filename = request_response/\RMBFILE . $row[0] . .zip;
open RMB,$filename;
binmode RMB;
print RMB $row[2];
$rmbcount++;
  }
}

What I want to do is extract the text file from each archive, rename it and
write to the same request_response directory. An example would be:

IMBFILE12345.zip (containing requestString) would become request12345.xml

Any ideas?

Regards,


DENNIS M. GRAY
Department of Immigration and Multicultural and Indigenous Affairs



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: sum a column

2004-09-30 Thread rmck
Are you serious. Im not sure how to sum up the column... I tried by using the 
field and * it by the increment.

I have written every part of my script, Im stuck on one part , summing a column

Man you need a vacation Gunnar should be Goner...



-Original Message-
From: Gunnar Hjalmarsson [EMAIL PROTECTED]
Sent: Sep 30, 2004 5:21 PM
To: [EMAIL PROTECTED]
Subject: Re: sum a column

Rmck wrote:
 Im trying to sum up a column from my results. Help.

job specification snipped

 Im stuck.

I don't believe you. To be stuck, you need to try first, and I suspect 
that you didn't do that. Note that this is not a free service for 
modifying scripts that people pick up somewhere.

I suggest that you make a serious attempt to solve the 'problem', and 
come back here if you encounter problems.

If you don't know any Perl at all, start here:

 http://learn.perl.org/

or hire a consultant to help you.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




Re: difference between @_ and shift

2004-09-30 Thread Chris Devers
On Thu, 30 Sep 2004, John W. Krahn wrote:

 Chris Devers wrote:
  
  shift is a function for pulling off the first element from a list.
 
 Wrong!  If you try to use shift() with a list it will print out a nice 
 error message Type of arg 1 to shift must be array.
 
 perldoc -q What is the difference between a list and an array

Whoops! I stand corrected. Sorry about that.

In any case, the bigger point is that @_ and shift are much different 
things -- they may be used in similar places, but that doesn't make them 
into synonyms.


 
-- 
Chris Devers

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response




  1   2   >