Re: how the print the first 7 letter of file name

2004-10-25 Thread Bernard Kenik
I was not trying to come up with an altenative regex to do what he might 
have wanted (first 7 characters or filename up to the underscore)

I was trying to understand what "[^/]*" did in your regex. I know that you 
said that it was to make sure that there was not any "/" after the 7 
characters. However I could not see the mechanics on how it would work.

Basically, I wanted a regex which would simply extract a pathname from a 
fully qualified filename and determine if "[^/]*" was needed  to obtain the 
complete pathname.

So I modified your regex to extract the pathname and throw away the basename 
... this showed me that
"[^/]*" was not required to traverse up to the last "/". The " .*/" part of 
the regex is greedy and grabs everything up to and including the last "/". 
This meant that "[^/]*" could be replaced with ".*" in your regex and still 
do the same thing...

- Original Message - 
From: "Chris Devers" <[EMAIL PROTECTED]>
To: "Bernard Kenik" <[EMAIL PROTECTED]>
Cc: "Perl Beginners List" <[EMAIL PROTECTED]>
Sent: Monday, October 25, 2004 12:30 AM
Subject: RE: how the print the first 7 letter of file name


On Sun, 24 Oct 2004, Bernard Kenik wrote:
The part that puzzled me was [^/] .. so I experimented a little.  I asked
myself how I would extract the path portion.
Wasn't the requirement to *throw away* the path portion, not save it?
The final answer I came up with was: ( my $path = $file ) =~ 
s#(.*/).*#$1#;
This extract all characters up to and including the last slash since this 
is a
greedy regex.
Wouldn't that save the path, but not the filename?
Isn't that the opposite of what the guy was asking for?
Therefore I concluded that "[^/]" would not be needed.
( my $name = $file ) =~ s#.*/(...).*$#$1#;  does the same thing as 
( my
$name = $file ) =~ s#.*/(...)[^/]*$#$1#;
Maybe so, but when I was testing it on the command line, the variant you
show was matching the first slash and the first 7 characters after it,
which isn't what the guy (seemed to be) asking for.
That said, I'm still not sure I had it right. He said he wanted the
first seven characters, which is what I was trying to write, but it
looks like he wanted the part of the filename before the underscore:
 $no_path_file = "NewProcess_date_22-oct-2004.log";
 ( my $prefix = $no_path_file ) =~ s/_.*//; print $prefix;
 print $prefix;
-- prints "NewProcess", which seems to be what he really wanted.
But he *still* never described the goal clearly, so that's as close as I
care to bother getting :-)
This is not meant as a criticism but simply to show that someone was
watching and learning.
We're all learning, hopefully -- I know I am... :-)

--
Chris Devers 

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



Re: problem printf

2004-10-25 Thread deny

   That isn't only perl code, it's incomplete, and it
doesn't use 'printf'.  Show us more code and explain
your problem fully.
 

thanks for your help
here is the complete code
#!/usr/bin/perl   

use MD5;
require 'find.pl';
$md5 = new MD5;
@dirs = @ARGV;
foreach $dir ( @dirs ) { find($dir); }
sub wanted { push @files, $name; }
foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
   $stat = sprintf "%0o", (stat_)[2];
   unless( -f $name ) {
   printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
   next;
   }
  
   $md5->reset();
   open FILE, $name or print(STDERR "can't open file $name\n"), next;
   $md5->addfile(FILE);
   close FILE;
  
   $checksum - $md5->hexdigest();
   printf "$stat\t$uid $gid $checksum\t$name\n";
}   

it aim to calcute sum permission on the dir in @ARGV;
and with diff ,you can see  if files was modified
but the result isnt fine as you can see below
[EMAIL PROTECTED] cgi-bin]$ ./checksum.pl /bin
0   /bin
0   /bin/arch
0   /bin/awk
0   /bin/basename
0   /bin/bash
0   /bin/bash2
0   /bin/cat
0   /bin/chgrp
0   /bin/chmod
thanks
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



how to give stdin at the end of a url

2004-10-25 Thread E.Horn
Hey!
I want to get information out of this page.
My problem is,how can i give ($eingabe)into the url?
Because that varies the output of the xmlsource!
exampe: $url=.term=gtpase...
gives me the result of all gtpases...how can i use a funktion or
variable to make it possible ti give it into the stdin an that gives the
content of stdin into the end of my url???


#!/usr/bin/perl -w
use LWP::Simple;

$eingabe=0;
chomp($eingabe =<>)


 $url =
'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/egquery.fcgi?term=$eingabe';




   $doc = get $url;
 print $doc;




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




LWP::Simple use proxy

2004-10-25 Thread Ramprasad A Padmanabhan
Hi All,

I am using LWP::Simple;
I want use of proxy  to be enabled from the environment.

In LWP::UserAgent there is a method env_proxy by which I can do this.
How can I do a similar thing for LWP::Simple;

Thanks
Ram



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




assign operator as variable

2004-10-25 Thread Khairul Azmi
I am not sure what category should this question fall under but this
is what I plan to do.

$cond1 = 1;
$cont2 = 0;
$oper1="&&"; # for AND
$oper2="||"; # for OR

if ($cond1 $oper1 $cond2) {
  print "one \n";
 } else {
  print "two \n";
}

The statement above would generates errors. Can somebody tell me how
to do it in proper way. Thanks

Azmi

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




Re: assign operator as variable

2004-10-25 Thread Gabor Urban
On Mon, 2004-10-25 at 11:39, Khairul Azmi wrote:
> I am not sure what category should this question fall under but this
> is what I plan to do.
> 
> $cond1 = 1;
> $cont2 = 0;
> $oper1="&&"; # for AND
> $oper2="||"; # for OR
> 
> if ($cond1 $oper1 $cond2) {
>   print "one \n";
>  } else {
>   print "two \n";
> }
> 
> The statement above would generates errors. Can somebody tell me how
> to do it in proper way. Thanks
> 
> Azmi

Hi, did you try to use the function eval? 

Check perldoc

I think this should help you.

Gabaux


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




Re: assign operator as variable

2004-10-25 Thread Khairul Azmi
Actually I am looking for an alternative to replace the conventional
symbol "&&" with other variable eg $AND_operator so that the following
statement is valid

if ($cond1 $AND_operator $cond2)

Thanks 


On Mon, 25 Oct 2004 10:44:19 +0100, Marcos Rebelo
<[EMAIL PROTECTED]> wrote:
> Maybe this can help
> 
> $a = "1 or 0"; print eval($a);
> 
> 
> 
> -Original Message-
> From: Khairul Azmi [mailto:[EMAIL PROTECTED]
> Sent: segunda-feira, 25 de Outubro de 2004 10:40
> To: [EMAIL PROTECTED]
> Subject: assign operator as variable
> 
> I am not sure what category should this question fall under but this
> is what I plan to do.
> 
> $cond1 = 1;
> $cont2 = 0;
> $oper1="&&"; # for AND
> $oper2="||"; # for OR
> 
> if ($cond1 $oper1 $cond2) {
>   print "one \n";
>  } else {
>   print "two \n";
> }
> 
> The statement above would generates errors. Can somebody tell me how
> to do it in proper way. Thanks
> 
> Azmi
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
>

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




RE: assign operator as variable

2004-10-25 Thread Marcos Rebelo
if (eval("$cond1 $AND_operator $cond2"))

is this correct?

-Original Message-
From: Khairul Azmi [mailto:[EMAIL PROTECTED] 
Sent: segunda-feira, 25 de Outubro de 2004 11:00
To: [EMAIL PROTECTED]
Subject: Re: assign operator as variable

Actually I am looking for an alternative to replace the conventional
symbol "&&" with other variable eg $AND_operator so that the following
statement is valid

if ($cond1 $AND_operator $cond2)

Thanks 


On Mon, 25 Oct 2004 10:44:19 +0100, Marcos Rebelo
<[EMAIL PROTECTED]> wrote:
> Maybe this can help
> 
> $a = "1 or 0"; print eval($a);
> 
> 
> 
> -Original Message-
> From: Khairul Azmi [mailto:[EMAIL PROTECTED]
> Sent: segunda-feira, 25 de Outubro de 2004 10:40
> To: [EMAIL PROTECTED]
> Subject: assign operator as variable
> 
> I am not sure what category should this question fall under but this
> is what I plan to do.
> 
> $cond1 = 1;
> $cont2 = 0;
> $oper1="&&"; # for AND
> $oper2="||"; # for OR
> 
> if ($cond1 $oper1 $cond2) {
>   print "one \n";
>  } else {
>   print "two \n";
> }
> 
> The statement above would generates errors. Can somebody tell me how
> to do it in proper way. Thanks
> 
> Azmi
> 
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
>

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




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




Re: assign operator as variable

2004-10-25 Thread Khairul Azmi
Yes. Silly me. I put the eval operator right before variable
$AND_operator. Thanks a lot guys.


On Mon, 25 Oct 2004 11:03:24 +0100, Marcos Rebelo
<[EMAIL PROTECTED]> wrote:
> if (eval("$cond1 $AND_operator $cond2"))
> 
> is this correct?
> 
> -Original Message-
> From: Khairul Azmi [mailto:[EMAIL PROTECTED]
> Sent: segunda-feira, 25 de Outubro de 2004 11:00
> To: [EMAIL PROTECTED]
> Subject: Re: assign operator as variable
> 
> Actually I am looking for an alternative to replace the conventional
> symbol "&&" with other variable eg $AND_operator so that the following
> statement is valid
> 
> if ($cond1 $AND_operator $cond2)
> 
> Thanks
> 
> On Mon, 25 Oct 2004 10:44:19 +0100, Marcos Rebelo
> <[EMAIL PROTECTED]> wrote:
> > Maybe this can help
> >
> > $a = "1 or 0"; print eval($a);
> >
> >
> >
> > -Original Message-
> > From: Khairul Azmi [mailto:[EMAIL PROTECTED]
> > Sent: segunda-feira, 25 de Outubro de 2004 10:40
> > To: [EMAIL PROTECTED]
> > Subject: assign operator as variable
> >
> > I am not sure what category should this question fall under but this
> > is what I plan to do.
> >
> > $cond1 = 1;
> > $cont2 = 0;
> > $oper1="&&"; # for AND
> > $oper2="||"; # for OR
> >
> > if ($cond1 $oper1 $cond2) {
> >   print "one \n";
> >  } else {
> >   print "two \n";
> > }
> >
> > The statement above would generates errors. Can somebody tell me how
> > to do it in proper way. Thanks
> >
> > Azmi
> >
> > --
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> >  
> >
> >
> 
> --
> 
> 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
>

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




Interactive socket client

2004-10-25 Thread mkondelk
I have this interactice client:
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($host, $port, $kidpid, $handle, $line);
unless (@ARGV == 2) { die "usage: $0 host port" }
($host, $port) = @ARGV;
# create a tcp connection to the specified host and port
$handle = IO::Socket::INET->new(Proto => "tcp",
   PeerAddr => $host,
   PeerPort => $port)
   or die "can't connect to port $port on $host: $!";
$handle->autoflush(1); # so output gets there right away
print STDERR "[Connected to $host:$port]\n";
# split the program into two processes, identical twins
die "can't fork: $!" unless defined($kidpid = fork());
# the if{} block runs only in the parent process
if ($kidpid) { 
   # copy the socket to standard output
   while (defined ($line = <$handle>)) {
   print STDOUT $line;
   }
   kill("TERM", $kidpid); # send SIGTERM to child
}
# the else{} block runs only in the child process
else { 
   # copy standard input to the socket
   while (defined ($line = )) {
   print $handle $line;
   }
}

on the server run this script:
#!perl -w
use IO::Socket;
$PORT = 7890;
$server = IO::Socket::INET-> new (LocalPort => $PORT,Listen => 5);
while ($client = $server->accept())
{
print $client "Command?\r\n";
$client->autoflush(1);
while ( <$client>)
{
if (/q/) { last; }
elsif (/dfc/) { print $client `dir /-C`."\r\n" ; }
print $client "Command?\r\n";
} 
close $client;
}


why don't work under WinXP? I have ASPerl 5.8. If I connect from telnet, 
client works  normally. Thanks.

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



memory usage of an array

2004-10-25 Thread Bryan Harris


The "books" say that you can add items to an array until you run out of
memory...  Is there any way for a script to see how much memory is in use so
far, versus how much there is left?

- B



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




Re: Limits on globbing?

2004-10-25 Thread Bryan Harris


> If thats so, here's something to keep you entertained.


Yet another script that doesn't work as received... To make it work I had to
remove line 1, and then it still threw a bunch of errors at runtime.

Still, it's pretty cool.  =)

- B



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




thx

2004-10-25 Thread Stefan Hans
Thx for the answer.

I just was following the install-instructions " It's all pure Perl, so just
put the .pm files in their appropriate local Perl subdirectories" and I had
only under /usr/lib/perl5/5.8.0/ *.pm-files. That is why I copied
RecDescent.pm there.

Later I did the perl-Makefile.PL-make-stuff under Parse-RecDescent-1.94 and
the problem was solved.

RecDescent.pm was put into
/usr/lib/perl5/site_perl/5.8.0/Parse/RecDescent.pm.

cu Stefan



- Original Message - 
From: "Gunnar Hjalmarsson" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Monday, October 25, 2004 12:34 AM
Subject: Re: Module Installation Question


> Stefan Hans wrote:
> > What I have done:
> >
> > # cp  ./lib/Parse/RecDescent.pm /usr/lib/perl5/5.8.0/
>
> 
>
> > My problem:
> >
> > Warning: prerequisite Parse::RecDescent 0 not found.
> >
> > Why can perl not find this RecDescent.pm under /usr/lib/perl5/5.8.0/ ?
>
> Because it does not look for it there, but it expects to find it in for
> instance /usr/lib/perl5/site_perl/5.8.0/Parse
>
> Why didn't you install also Parse::RecDescent using Makefile.PL etc.?
> Then you had probably not encountered this problem.
>
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>



Re: thx

2004-10-25 Thread Gunnar Hjalmarsson
Stefan Hans wrote:
Gunnar Hjalmarsson wrote:
Why didn't you install also Parse::RecDescent using Makefile.PL
etc.?
I just was following the install-instructions " It's all pure Perl,
so just put the .pm files in their appropriate local Perl
subdirectories"
Hmm..  That works, of course, if you know what's an "appropriate" directory.
I'm surprised that that's the *only* option mentioned. Wonder if Mr.
Conway has seen
perldoc -q "install a module"
:)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: problem printf

2004-10-25 Thread Owen
On Mon, 25 Oct 2004 05:17 pm, deny wrote:
> foreach $name ( sort @files) {
>     ($uid,$gid) = (stat $nane)[4,5];

stat $nane or $name?

Owen

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




Re: problem printf

2004-10-25 Thread Flemming Greve Skovengaard
deny wrote:

   That isn't only perl code, it's incomplete, and it
doesn't use 'printf'.  Show us more code and explain
your problem fully.
 

thanks for your help
here is the complete code
#!/usr/bin/perl  
use MD5;
require 'find.pl';

$md5 = new MD5;
@dirs = @ARGV;
foreach $dir ( @dirs ) { find($dir); }
sub wanted { push @files, $name; }
foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
   $stat = sprintf "%0o", (stat_)[2];
   unless( -f $name ) {
   printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
   next;
   }
 $md5->reset();
   open FILE, $name or print(STDERR "can't open file $name\n"), next;
   $md5->addfile(FILE);
   close FILE;
 $checksum - $md5->hexdigest();
   printf "$stat\t$uid $gid $checksum\t$name\n";
}  

it aim to calcute sum permission on the dir in @ARGV;
and with diff ,you can see  if files was modified
but the result isnt fine as you can see below
[EMAIL PROTECTED] cgi-bin]$ ./checksum.pl /bin
0   /bin
0   /bin/arch
0   /bin/awk
0   /bin/basename
0   /bin/bash
0   /bin/bash2
0   /bin/cat
0   /bin/chgrp
0   /bin/chmod
thanks

Try to add this lines somewhere the top of the file:
use strict;
use warnings;
and report the errors, if any.
--
Flemming Greve Skovengaard   Just a few small tears between
a.k.a Greven, TuxPower   Someone happy and one sad
<[EMAIL PROTECTED]>  Just a thin line drawn between
4112.38 BogoMIPS Being a genius or insane
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: how to give stdin at the end of a url

2004-10-25 Thread Chris Devers
 On Mon, 25 Oct 2004, E.Horn wrote:

> I want to get information out of this page.
> My problem is, how can i give ($eingabe) into the url?
> Because that varies the output of the xmlsource!
>
> example:
>
>   $url=.term=gtpase...
>
> gives me the result of all gtpases...
> 
> How can I use a function or variable to make it possible to give it 
> into the stdin and that gives the content of stdin into the end of my 
> url???
> 
>   #!/usr/bin/perl -w
>   use LWP::Simple;
> 
>   $eingabe=0;
>   chomp($eingabe =<>)
> 
>   $url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/egquery.fcgi?term=$eingabe';
> 
>   $doc = get $url;
>   print $doc;

What counts as valid input? You're not doing any kind of checks here, so 
the user can upload just about anything to the site. Chances are 
excellent that this will allow Bad Things to Happen on the receiving 
end, if not on your end. Anything at all you can do to validate $eingabe 
before sending it to the nih.gov server would be worth doing. 

But that's as an aside. 

What happens when you pass the script canned values for $eingabe to use?

   #!/usr/bin/perl -w
   use LWP::Simple;

   $url = 'http://eutils.ncbi.nlm.nih.gov/entrez/eutils/egquery.fcgi?term=';

   $eingabe = "gtpase";
 
   $doc = get "$url$eingabe";
   print $doc;
 
That works, right?

If so, maybe the right approach is to pass the script arguments when it 
is invoked rather than pulling them in after launch on standard input. 
Take a look at a module like Getopt::Std and Getopt::Long to do this:

Getopt::Std:

   use warnings;
   use strict;
   use Getopt::Std;

   my %opts;
   getopt('a');
  # sets $opts{'a'} to whatever the user put for '-a ...'

Getopt::Long:

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

   my $eingabe;
   my $result = GetOptions ( "arg=s" => \$eingabe );
  # sets $eingabe to whatever the user put for '--arg=...'

I believe these modules are bundled with most versions of Perl 5.x. Look 
up the documentation in `perldoc Getopt::Std` & `perldoc Getopt::Long`.



-- 
Chris Devers

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




Re: how to give stdin at the end of a url

2004-10-25 Thread E.Horn
thanks a lot!
I will look at this!
I have done it my way and i think now it works...
I think it is not the best way,but i am happy with it!
I learn perl for a week now...i am proud that is gives any result!

#!/xprog/bin/perl -w
use LWP::Simple;

sub daten_einlesen
{
printf "geben Sie ein gtpprotein ein\n";
 my $eingabe =;
 my $url='http://eutils.ncbi.nlm.nih.gov/entrez/eutils/egquery.fcgi?term='
$newurl= $url.$eingabe;
 return $newurl;




}

$url1 =daten_einlesen();
$doc = get $url1;
print $doc;




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




Re: problem printf

2004-10-25 Thread Jenda Krynicky
From: deny <[EMAIL PROTECTED]>
> here is the complete code
> 
> #!/usr/bin/perl   
> 
> use MD5;
> require 'find.pl';
> 
> $md5 = new MD5;
> @dirs = @ARGV;
> 
> foreach $dir ( @dirs ) { find($dir); }
> sub wanted { push @files, $name; }
> 
> foreach $name ( sort @files) {
> ($uid,$gid) = (stat $nane)[4,5];
> $stat = sprintf "%0o", (stat_)[2];
> unless( -f $name ) {
> printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";

You should either be using print():

print "$stat\t$uid $gid\t\t\t\t\t\t$name\n";

or use printf() the way it was meant tu be. The first argument to 
printf should be "format", then you should specify the variables:

printf "%d\t%d %d\t\t\t\t\t\t%s\n", $stat, $uid, $gid, $name; 

I think the other problem is that you only store the names of the 
files, not paths in the @files array. So stat() is not able to find 
the files.

If would probably be best to do the stat() and print the result 
directly from the wanted() subroutine.

Jenda
P.S.: What the heck is find.pl? You should be using File::Find!

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


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




Re: How to remove trailing zero

2004-10-25 Thread John W. Krahn
Khairul Azmi wrote:
Can somebody help me how to remove the trailing zero from an ip address
$ip_add = "010.200.020.000";
The output should be "10.200.20.0";
I''ve been trying many regex techniques but still unsuccessful. 
$ perl -le'$_ = "010.200.020.000"; print; s/\b0+(?=\d)//g; print'
010.200.020.000
10.200.20.0
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Populating HASH from file

2004-10-25 Thread Jeff Borders
Newbie here,

I need to dump a plain text file that has the format of:

key = value (ie. question  answer)

into a hash.  I'm writing a simple learning tool to help me learn some
basic korean terminology.

Would someone be kind enough to point me in the right direction.

-Jeff Borders

korean.txt:

One = Hana
Two = Dool
Three = Set
etc.

*

#!/usr/bin/perl

%dictionary=("",,)

@answers=keys(%dictionary);
@questions=values(%dictionary);

open(DICT,") {
  chomp($word);

#  if ($word eq "=") {
#  }
#  print "$word\n";
}
close(DICT);






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




Re: Populating HASH from file

2004-10-25 Thread Jeff 'japhy' Pinyan
On Oct 25, Jeff Borders said:

>I need to dump a plain text file that has the format of:
>
>key = value (ie. question  answer)
>
>into a hash.  I'm writing a simple learning tool to help me learn some
>basic korean terminology.
>
>Would someone be kind enough to point me in the right direction.

You want to start with an empty hash:

  my %dict;

Then, when you're looping over each line of the file:

  while () {

you'll want to remove the ending newline,

chomp;

and split it on the = character (with whitespace on either side):

my ($term, $def) = split /\s*=\s*/;

Then you want to put that pair into the hash:

$dict{$term} = $def;
  }

Using the hash, and opening the file, I leave up to you.

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


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




Re: Populating HASH from file

2004-10-25 Thread John W. Krahn
Jeff Borders wrote:
I need to dump a plain text file that has the format of:
key = value (ie. question  answer)
into a hash.  I'm writing a simple learning tool to help me learn some
basic korean terminology.
Would someone be kind enough to point me in the right direction.
-Jeff Borders
korean.txt:
One = Hana
Two = Dool
Three = Set
etc.
*
#!/usr/bin/perl
%dictionary=("",,)
@answers=keys(%dictionary);
@questions=values(%dictionary);
open(DICT,") {
  chomp($word);
#  if ($word eq "=") {
#  }
#  print "$word\n";
}
close(DICT);
It sounds like you need something like this:
#!/usr/bin/perl
use warnings;
use strict;
open DICT, '<', 'korean.txt' or die "Cannot open 'korean.txt' $!";
my %dictionary = map /^([^=]+)=(.+)/, ;
close DICT;

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Populating HASH from file

2004-10-25 Thread Edward WIJAYA
Hi,
Mine is not as elegant as J.Krahn's or Jeff's.
But it's an alternative.
I am just glad to contribute at least something
to the forum I have owed so much...
--
Regards,
Edward WIJAYA
SINGAPORE
---
use strict;
use warnings;
use Data::Dumper;
my %hash = ();
while () {
s/\s//g;
/(\w+)=(\w+)/;
$hash{$1} = $2;
}
print Dumper \%hash;
__DATA__
One = Hana
Two = Dool
Three = Set
--
output:
$VAR1 = {
  'Three' => 'Set',
  'Two' => 'Dool',
  'One' => 'Hana'
};
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: problem printf

2004-10-25 Thread John W. Krahn
deny wrote:

   That isn't only perl code, it's incomplete, and it
doesn't use 'printf'.  Show us more code and explain
your problem fully.
thanks for your help
here is the complete code
#!/usr/bin/perl  
use warnings;
use strict;
use MD5;
use Digest::MD5;
require 'find.pl';
use File::Find;
$md5 = new MD5;
my $md5 = Digest::MD5->new;
@dirs = @ARGV;
foreach $dir ( @dirs ) { find($dir); }
my @files;
find( \&wanted, @ARGV );
sub wanted { push @files, $name; }
You need to push the complete path into the array:
sub wanted { push @files, $File::Find::name }
foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
 my ( $uid, $gid ) = ( stat $name )[ 4, 5 ];
   $stat = sprintf "%0o", (stat_)[2];
 ^
If you had strictures enabled (use strict) then perl would have informed you 
of this error and refused to compile your code.

 my $stat = sprintf '%o', (stat _)[2];
   unless( -f $name ) {
 unless( -f _ ) {
   printf "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
 print "$stat\t$uid $gid\t\t\t\t\t\t$name\n";
   next;
   }
 $md5->reset();
   open FILE, $name or print(STDERR "can't open file $name\n"), next;
You should include the $! variable in the error message so you know *why* it 
failed.

   $md5->addfile(FILE);
   close FILE;
 $checksum - $md5->hexdigest();
   printf "$stat\t$uid $gid $checksum\t$name\n";
 print "$stat\t$uid $gid $checksum\t$name\n";
}  

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Populating HASH from file

2004-10-25 Thread John W. Krahn
Edward WIJAYA wrote:
Mine is not as elegant as J.Krahn's or Jeff's.
But it's an alternative.
I am just glad to contribute at least something
to the forum I have owed so much...
---
use strict;
use warnings;
use Data::Dumper;
my %hash = ();
while () {
s/\s//g;
You may be removing too many whitespace characters if any of the fields has 
embedded whitespace.

/(\w+)=(\w+)/;
$hash{$1} = $2;
You should only use the digit variables ($1, $2, etc.) if the match was 
successful or their contents will be left over from the last successful match.

}

John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Strange Error

2004-10-25 Thread Mike Blezien
Gunnar Hjalmarsson wrote:
Mike Blezien wrote:
What does this type of error indicate, I never encountered this type 
of error before.

-
Modification of a read-only value attempted at
/home/www/cgi/somescript.cgi line 151.
-

my($sparam);
foreach $sparam (param()) { ${$sparam} = param($sparam); } # line 151
--
Maybe it's that; hard to tell since you don't give more context. But 
what you are trying to do, i.e. using symbolic references, is 
unnecessary and considered bad programming practice.

The standard way to avoid it is to use a hash instead of a bunch of 
scalars. In the case of CGI parameters, you can simply do e.g.:

use CGI;
my %param = new CGI->Vars;
That would give you all the parameters conveniently available in the 
%param hash.
Thanks for the suggestion. We've used this type of coding scheme before with no 
problems in the past, but wasn't aware it was considered "bad programming" 
practice.

Regards,
--
Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
Providing Internet Solutions that work!
http://thunder-rain.com/
Tel: 1.712.395.0670
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



parse xml

2004-10-25 Thread E.Horn
Hey!
How can i pars this xmlfile?
i just want to have the geo and the count  out of
this...


  geo
  GEO Profiles
  69408
  Ok
 

 
  gds
  GEO DataSets
  8
  Ok
 

  regards eve


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




Re: parse xml

2004-10-25 Thread Traeder, Philipp
On Monday 25 October 2004 16:27, E.Horn wrote:
> Hey!
> How can i pars this xmlfile?
> i just want to have the geo and the count  out of
> this...
>
[..]

Hi,

I can highly recommend XML::Simple - just use it like this:

#!/usr/bin/perl -w

use strict;
use XML::Simple; 
use Data::Dumper;

my $ref = XMLin('xmlin.xml');

# now you've got the whole XML file in $ref:
print Dumper($ref);
print "\n";

print $ref->{'ResultItem'}->[0]{'MenuName'};
print "\t";
print $ref->{'ResultItem'}->[0]{'Count'} . "\n";

__END__

Now you can walk over the hash/array structure and everything's fine :-)

HTH,

Philipp


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




Re: problem printf

2004-10-25 Thread deny
Owen a écrit :
On Mon, 25 Oct 2004 05:17 pm, deny wrote:
 

foreach $name ( sort @files) {
   ($uid,$gid) = (stat $nane)[4,5];
   

stat $nane or $name?
 

$name ,
error for me ,the result is the same
if someone want the script for test
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Strange Error

2004-10-25 Thread Gunnar Hjalmarsson
Mike Blezien wrote:
Gunnar Hjalmarsson wrote:
Mike Blezien wrote:
foreach $sparam (param()) { ${$sparam} = param($sparam); } # line 151
-
Maybe it's that; hard to tell since you don't give more context. But 
what you are trying to do, i.e. using symbolic references, is 
unnecessary and considered bad programming practice.

The standard way to avoid it is to use a hash instead of a bunch of 
scalars. In the case of CGI parameters, you can simply do e.g.:

use CGI;
my %param = new CGI->Vars;
That would give you all the parameters conveniently available in the 
%param hash.
Thanks for the suggestion. We've used this type of coding scheme before 
with no problems in the past, but wasn't aware it was considered "bad 
programming" practice.
It's explained in the Perl FAQ:
perldoc -q "variable name"
Sorry for not providing that reference in the first place. ;-)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



perl.beginners Weekly list FAQ posting

2004-10-25 Thread casey
NAME
beginners-faq - FAQ for the beginners mailing list

1 -  Administriva
  1.1 - I'm not subscribed - how do I subscribe?
Send mail to <[EMAIL PROTECTED]>

You can also specify your subscription email address by sending email to
(assuming [EMAIL PROTECTED] is your email address):

<[EMAIL PROTECTED]>.

  1.2 -  How do I unsubscribe?
Now, why would you want to do that? Send mail to
<[EMAIL PROTECTED]>, and wait for a response. Once you
reply to the response, you'll be unsubscribed. If that doesn't work,
find the email address which you are subscribed from and send an email
like the following (let's assume your email is [EMAIL PROTECTED]):

<[EMAIL PROTECTED]>

  1.3 - There is too much traffic on this list. Is there a digest?
Yes. To subscribe to the digest version of this list send an email to:

<[EMAIL PROTECTED]>

To unsubscribe from the digest, send an email to:

<[EMAIL PROTECTED]>

This is a high traffic list (100+ messages per day), so please subscribe
in the way which is best for you.

  1.4 - Is there an archive on the web?
Yes, there is. It is located at:

http://archive.develooper.com/beginners%40perl.org/

  1.5 - How can I get this FAQ?
This document will be emailed to the list once a week, and will be
available online in the archives, and at http://learn.perl.org/

  1.6 - I don't see something in the FAQ, how can I make a suggestion?
Send an email to <[EMAIL PROTECTED]> with your suggestion.

  1.7 - Is there a supporting website for this list?
Yes, there is. It is located at:

http://beginners.perl.org/

  1.8 - Who do I complain to?
You can send complaints to <[EMAIL PROTECTED]>

  1.9 - Who currently maintains the FAQ?
Kevin Meltzer, who can be reached at the email address (for FAQ
suggestions only) in question 1.6

  1.10 - Who will maintain peace and flow on the list?
Casey West, Kevin Meltzer and Ask Bjoern Hansen currently carry large,
yet padded, clue-sticks to maintain peace and order on the list. If you
are privately emailed by one of these folks for flaming, being
off-topic, etc... please listen to what they say. If you see a message
sent to the list by one of these people saying that a thread is closed,
do not continue to post to the list on that thread! If you do, you will
not only meet face to face with a XQJ-37 nuclear powered pansexual
roto-plooker, but you may also be taken off of the list. These people
simply want to make sure the list stays topical, and above-all, useful
to Perl beginners.

  1.11 - When was this FAQ last updated?
Feb 04, 2004

2 -  Questions about the 'beginners' list.
  2.1 - What is the list for?
A list for beginning Perl programmers to ask questions in a friendly
atmosphere.

  2.2 - What is this list _not_ for?
* SPAM
* Homework
* Solicitation
* Things that aren't Perl related
* Monkeys
* Monkeys solicitating homework on non-Perl related SPAM.

  2.3 - Are there any rules?
Yes. As with most communities, there are rules. Not many, and ones that
shouldn't need to be mentioned, but they are.

* Be nice
* No flaming
* Have fun

  2.4 - What topics are allowed on this list?
Basically, if it has to do with Perl, then it is allowed. You can ask
CGI, networking, syntax, style, etc... types of questions. If your
question has nothing at all to do with Perl, it will likely be ignored.
If it has anything to do with Perl, it will likely be answered.

  2.5 - I want to help, what should I do?
Subscribe to the list! If you see a question which you can give an
idiomatic and Good answer to, answer away! If you do not know the
answer, wait for someone to answer, and learn a little.

  2.6 - Is there anything I should keep in mind while answering?
We don't want to see 'RTFM'. That isn't very helpful. Instead, guide the
beginner to the place in the FM they should R :)

Please do not quote the documentation unless you have something to add
to it. It is better to direct someone to the documentation so they
hopefully will read documentation above and beyond that which answers
their question. It also helps teach them how to use the documentation.

  2.7 - I don't want to post a question if it is in an FAQ. Where should I
look first?
Look in the FAQ! Get acquainted with the 'perldoc' utility, and use it.
It can save everyone time if you look in the Perl FAQs first, instead of
having a list of people refer you to the Perl FAQs :) You can learn
about 'perldoc' by typing:

"perldoc perldoc"

At your command prompt. You can also view documentation online at:

http://www.perldoc.com and http://www.perl.com

  2.8 Is this a high traffic list?
YES! You have been warned! If you don't want to get ~100 emails per day
from this list, consider subscribing to the digest.

  2.9 Other tips before posti

Re: parse xml

2004-10-25 Thread Jenda Krynicky
From: "Traeder, Philipp" <[EMAIL PROTECTED]>
> print $ref->{'ResultItem'}->[0]{'MenuName'};

I think it's better to either skip all the -> between subscriptions 
or include them all:

print $ref->{'ResultItem'}[0]{'MenuName'};
or
print $ref->{'ResultItem'}->[0]->{'MenuName'};

It doesn't really matter of course.

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]
 




syntax differences and performance

2004-10-25 Thread Adamiec, Larry
Given the following lines:

$MESSAGE .= "Application Fee: " . $price . " Dollars U.S.";

$MESSAGE .= "Application Fee: $price Dollars U.S.";


Is there a performance issue (or any other issue) for using either of
the above lines?  Does it make any difference which is used?

Suppose it changed to the following:

$MESSAGE .= "Application Fee: " . $query-param('price') . "
Dollars U.S.";

or

$MESSAGE .= "Application Fee: $query-param('price') Dollars
U.S.";

I have used the first two lines without any noticeable difference, but I
didn't use any sort of debugging/timer tools either.  I am debating with
myself about which line from the second set I should use.  In all
instances the correct value of "price" was inserted into the variable
$MESSAGE.

Larry


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




Re: syntax differences and performance

2004-10-25 Thread Steve Bertrand
> Given the following lines:
>
> $MESSAGE .= "Application Fee: " . $price . " Dollars U.S.";
>
> $MESSAGE .= "Application Fee: $price Dollars U.S.";
>
>
> Is there a performance issue (or any other issue) for using either of
> the above lines?  Does it make any difference which is used?
>
> Suppose it changed to the following:
>
> $MESSAGE .= "Application Fee: " . $query-param('price') . "
> Dollars U.S.";
>
> or
>
> $MESSAGE .= "Application Fee: $query-param('price') Dollars
> U.S.";
>
> I have used the first two lines without any noticeable difference, but
> I
> didn't use any sort of debugging/timer tools either.  I am debating
> with
> myself about which line from the second set I should use.  In all
> instances the correct value of "price" was inserted into the variable
> $MESSAGE.

Check out:

# perldoc Benchmark

HTH,

Steve

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



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




Re: syntax differences and performance

2004-10-25 Thread Brian Gerard
And the clouds parted, and Adamiec, Larry said...
> Given the following lines:
> 
> $MESSAGE .= "Application Fee: " . $price . " Dollars U.S.";
> 
> $MESSAGE .= "Application Fee: $price Dollars U.S.";
> 
> 
> Is there a performance issue (or any other issue) for using either of
> the above lines?  Does it make any difference which is used?
> 
> Suppose it changed to the following:
> 
> $MESSAGE .= "Application Fee: " . $query-param('price') . "
> Dollars U.S.";
> 
> or
> 
> $MESSAGE .= "Application Fee: $query-param('price') Dollars
> U.S.";
> 
> I have used the first two lines without any noticeable difference, but I
> didn't use any sort of debugging/timer tools either.  I am debating with
> myself about which line from the second set I should use.  In all
> instances the correct value of "price" was inserted into the variable
> $MESSAGE.
> 
> Larry

Hi Larry-

The first thing I would suggest is to check out the Benchmark::Timer
module off of CPAN.  You can time just about any section of your code
and print a report at the end to help you see where your optimization
time would best be spent.  Let me know if you would like some example
code to see how to use it.

Using this and a simple (contrived) script, I ran some tests and it
looks like the inline versions ("foo $var bar") might be slightly slower
than their "append" counterparts ("foo " . $var . " bar"), although the
timings sometimes drifted in the other direction based on how many trials
I ran (more trials == inline gets faster), a result I suspect can be
attributed to caching at some level.  Basically, there wasn't enough
deviation to be able to point to either one as significantly slower than
the other.  One of the heavier technical perldocs may have the answer, but
I did a quick scan through 'perldoc perltoc' and nothing jumped off the
page at me.  YMMV.

So I would suggest running *your*own* tests on some test data of your own
to get a better idea what will work best in *your* environment.  Also keep
in mind that unless your script does several thousand of these assignments
or your benchmarking shows that the majority of your script's runtime is
spent in these assignments, you probably won't see much of a difference
in performance by figuring out which one saves you 3 ms over the other. :)
I'm all for optimizing code just for the sake of good programming, but
if you're trying to ameliorate a performance problem, you want to look for
the part of your script where it's spending the most time.

HTH-
Brian


PS - $query-param('price') should be $query-param{'price'} - curly
 brackets for hashes, parens for subroutines.


  /~~\
 | Brian Gerard Dawn is nature's way of telling you to|
 | First initial + 'lists'  go to bed. And to just stay there until   |
 | at technobrat dot com  the evil yellow disk is gone again. |
  \__/

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




Re: syntax differences and performance

2004-10-25 Thread JupiterHost.Net

Steve Bertrand wrote:
Given the following lines:
$MESSAGE .= "Application Fee: " . $price . " Dollars U.S.";
$MESSAGE .= "Application Fee: $price Dollars U.S.";
In that case it seems a bit pointless to do the first way as there are 
now 3 things instead of 1 to deal with. the Benchmark module will help a 
lot :)

Is there a performance issue (or any other issue) for using either of
the above lines?  Does it make any difference which is used?
Suppose it changed to the following:
$MESSAGE .= "Application Fee: " . $query-param('price') . "
Dollars U.S.";
or
$MESSAGE .= "Application Fee: $query-param('price') Dollars
U.S.";
You mean: $query->param('price') right? :)
if you're doing something like that or a function thats a good way to do 
it but don't if you don't need to.
benchmark will tell you how they compare.

I have used the first two lines without any noticeable difference, but
I
didn't use any sort of debugging/timer tools either.  I am debating
with
myself about which line from the second set I should use.  In all
instances the correct value of "price" was inserted into the variable
$MESSAGE
Here's a benchmark I did:
Benchmark: timing 200 iterations of all one, with dots...
   all one: 0.839485 wallclock secs ( 0.78 usr +  0.00 sys =  0.78 CPU) 
@ 2564102.56/s (n=200)
 with dots: 0.975471 wallclock secs ( 1.01 usr + -0.01 sys =  1.00 CPU) 
@ 200.00/s (n=200)
   Rate with dots   all one
with dots 200/s--  -22%
all one   2564103/s   28%--

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



Re: parse xml

2004-10-25 Thread Philipp Traeder
On Monday 25 October 2004 16:49, Jenda Krynicky wrote:
> From: "Traeder, Philipp" <[EMAIL PROTECTED]>
>
> > print $ref->{'ResultItem'}->[0]{'MenuName'};
>
> I think it's better to either skip all the -> between subscriptions
> or include them all:
>
>   print $ref->{'ResultItem'}[0]{'MenuName'};
> or
>   print $ref->{'ResultItem'}->[0]->{'MenuName'};
>

You're right - I should have taken another look at this before posting.
My main focus was on pointing out XML::Simple combined with Data::Dumper -  
though this is *not* an excuse ;-).

Philipp

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




array of references

2004-10-25 Thread Scott Pham
I've been thinking about this and not sure how to approach this problem.
Say I want to create an array of 4 array references, thats easy since I
know that there will be 4 array references, how would I do this
dynamically? Say if one I only needed 2 references and another I need 10
array references, is there a way to do this in perl?

Thanks in advance.


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




RE: array of references

2004-10-25 Thread Ed Christian
Scott Pham wrote:
> I've been thinking about this and not sure how to approach this
> problem. Say I want to create an array of 4 array references, thats
> easy since I know that there will be 4 array references, how would I
> do this dynamically? Say if one I only needed 2 references and
> another I need 10 array references, is there a way to do this in
> perl? 

#!/usr/bin/perl -w
use warnings;
use strict;

my @array;
my $num_child_arrays = 10;

for (my $count = 0; $count < $num_child_arrays; $count++) {
my $array_ref = [ ];
push (@array,$array_ref);
}



Could probably be done in a shorter format as well...

push (@array,[]) for (1..$num_child_arrays);


For more info:

perldoc -f push


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




Re: uninstall perlmodule

2004-10-25 Thread Adam Saeed
one can uninstall the perl module.. by 
cd 
make distclean
 or 
just remove the path of perl module...
or remove the path from env. table.


On Sat, 23 Oct 2004 21:17:05 -0400 (EDT), Chris Devers
<[EMAIL PROTECTED]> wrote:
> On Sat, 23 Oct 2004, Bob Showalter wrote:
> 
> > I forgot to add. If you're on FreeBSD, you can remove a module with
> > pkg_delete (even if you installed it using CPAN and not from a port or
> > package). Your OS may have such a tool.
> 
> On Debian (or Debian based systems like Gentoo or Fink), you can
> 
>   apt-get remove foo-package-pm
> 
> to remove something that was installed with apt-get.
> 
> I'm sure it's also possible to do this with RPM managed packages.
> 
> But then, we have no idea what platform we're dealing with, what package
> needs to be removed, or how it was installed in the first place.
> 
> --
> Chris Devers
> 


-- 
Allah Hafiz
O! God Thy sea is so great and my boat is so small.
Adam

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




Re: foreach..

2004-10-25 Thread Dave Gray
> this is actual part of my code.. all work but it seems that something is
> wrong in foreach part.. in reality script calculate $dodatne_opcije only!
> $vrsta_paketa is not added in calculation..
> 
> my $vrsta_paketa = {
> '20MB' => 205,
> '50MB' => 270,
> '100MB' => 350,
> '200MB' => 450,
> '500MB' => 550,
> '1000MB' => 750
> };
> 
> my $dodatne_opcije = {
> 'Subdomene' => 73,
> 'ASP' => 70,
> 'SSL' => 440,
> 'Java' => 40
> };
> 
> foreach(keys %{$dodatne_opcije}){
> if($forma->{$_} eq $_){
> $cena +=  $dodatne_opcije->{$_};
> }
> }
> 
> my $pdv = 0.22 * $cena;
> 
> my $ukupno = $pdv + $cena;

I don't speak ... Croatian? But it sounds like you want to loop over
both hashes...? You can do that for $vrsta_paketa the same way you
already do it for $dodatne_opcije.

Cheers,
Dave

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




Re: Generate a perl list file

2004-10-25 Thread rs
>
> Dear all.
>
> I have a tab delimited file as follow:
>
> V namep
> 1.0   AAA 0.001
> 0.9   BBB 0.003
> 0.8   CCC 0.004
> .
>
> I need to convert the file into following format:
> { labels =
>   (
>   {v="1.0"; name = "AAA"; p = "0.001"; },
>   {v="0.9"; name = "BBB"; p = "0.003";},
>   {v="0.8"; name = "CCC"; p = "0.004";}
>   );
> }

Hi,
Here is my little contribution. Im a newbie myself... I may not have
understood your question completely, but here is some code that writes to
a file in the format that you have described above.

thx,
radhika

=
#!/usr/bin/perl -w

use strict;
use diagnostics;

#{v="1.0"; name = "AAA"; p = "0.001"; },
#{v="0.9"; name = "BBB"; p = "0.003";},
#{v="0.8"; name = "CCC"; p = "0.004";}

my $file = "data.txt";  #file read from
my $outfile = "data_out.txt"; #file to write to

my @header = ("v", "name", "p");

open(DATA, "<$file") or die "Cannot Open - $!\n";
open(OUT, ">$outfile") or die "$!\n";

print OUT "labels=\n";
print OUT "\(\n";
while (  ) {  #while loop to read first line only

if( $_ =~ /(\d+)\s+(\w+)\s+(\d+)/ ) {

print OUT "\{$header[0]=\"$1\"\; ";
print OUT "$header[1]=\"$2\"\; ";
print OUT "$header[2]=\"$3\"\; \}\n";
}
}



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




questions

2004-10-25 Thread M. Ilyas Hassan
hi,
Could someone please help me with the following perl questions.
#1 - Is there a way to add "days" to a date? I want 
end_date=start_date+90days; where start_date is in the format 10/25/04; the 
output end_date should be in the same format as well. I was not successful 
loading the Date::Calc module from CSPAN on ActivePerl 5 (Revision 5, 
version 6, Subrevision 1, - 5.006001). Can some suggest some input.

#2 - How could I find the minimum value from table with say 80columns. The 
numbers are stored in columns across (from column 2 to column 6). The output 
from the input table should retrieve the minimum value for each unique item 
in column 0. Does Perl have aggregate function to get minimum/average and 
other statistical values? How should the array/hash be structured.

Please email your feedback to [EMAIL PROTECTED] I will truly appreciate 
any help that you could offer.

Regards,
Hassan

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



Re: array of references

2004-10-25 Thread Zeus Odin
push @array, [] while @array < 10;
also works.


"Ed Christian" <[EMAIL PROTECTED]> wrote...

push (@array,[]) for (1..$num_child_arrays);

For more info:

perldoc -f push



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




Re: questions

2004-10-25 Thread Gunnar Hjalmarsson
M. Ilyas Hassan wrote:
#1 - Is there a way to add "days" to a date? I want 
end_date=start_date+90days; where start_date is in the format
10/25/04; the output end_date should be in the same format as well. I
was not successful loading the Date::Calc module from CSPAN on
ActivePerl 5 (Revision 5, version 6, Subrevision 1, - 5.006001). Can
some suggest some input.
The standard module Time::Local and the core function localtime() should
be sufficient. The solution at
http://groups.google.com/groups?selm=2pcclbFj9gkjU1%40uni-berlin.de
may give you some ideas.
#2 - How could I find the minimum value from table with say
80columns. The numbers are stored in columns across (from column 2 to
column 6). The output from the input table should retrieve the
minimum value for each unique item in column 0. Does Perl have
aggregate function to get minimum/average and other statistical
values? How should the array/hash be structured.
I pass that one. But I think you need to provide some sample data, and a
serious attempt to solve the problem.
Please email your feedback to [EMAIL PROTECTED]
This is a public mailing list, not a private helpdesk. (I sent you a
copy, but you should really subscribe to the list if you haven't already.)
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: questions

2004-10-25 Thread JupiterHost.Net
hi,
Hello,
Could someone please help me with the following perl questions.

#1 - Is there a way to add "days" to a date? I want 
end_date=start_date+90days; where start_date is in the format 10/25/04; 
the output end_date should be in the same format as well. I was not 
successful loading the Date::Calc module from CSPAN on ActivePerl 5 
(Revision 5, version 6, Subrevision 1, - 5.006001). Can some suggest 
some input.
search.cpan.org
Date::Calc
#2 - How could I find the minimum value from table with say 80columns. 
The numbers are stored in columns across (from column 2 to column 6). 
The output from the input table should retrieve the minimum value for 
each unique item in column 0. Does Perl have aggregate function to get 
minimum/average and other statistical values? How should the array/hash 
be structured.
search.cpan.org
DBI

Please email your feedback to [EMAIL PROTECTED] I will truly 
We will post back to the list so everyone can share. If want personal 
consulting and development feel free to contact me offlist for a quote ;p

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



Re: questions

2004-10-25 Thread Chris Devers
On Mon, 25 Oct 2004, M. Ilyas Hassan wrote:

> #1 - Is there a way to add "days" to a date?

The modules that the other two respondants pointed you to are the right 
way to do this, but it's good to know that the way to do this by hand -- 
which you won't want to do, but it's good to see why not -- is to only 
deal with times represented as seconds. 

So, for example, 90 days works out to 7776000 seconds (60 secs/min * 60 
mins/hour * 24 hours/day * 90 days).

So you look up the Unix timestamp for the starting date. For this, let's 
use the time as I type this, 1098746228:

$ perl -le 'print scalar localtime 1098746228'
Mon Oct 25 19:17:08 2004
$

You add 90 days worth of seconds to that to get the future date:

$ perl -le 'print 1098746228 + 7776000'
110658
$

And then you convert that back to a more conventional format:

$ perl -le 'print scalar localtime( 1098746228 + 7776000 )'
Sun Jan 23 18:17:08 2005
$

Or, putting it all together:

$ perl -le '$now = 1098746228; $ninety_days = 7776000; $then = $now + 
$ninety_days; print scalar localtime $then'
Sun Jan 23 18:17:08 2005
$

This isn't *that* bad, but the math gets annoying to manage manually. 
Using a module like Date::Calc saves a lot of effort & reduces errors. 

Look up the documentation for Date::Calc for usage detals.

> #2 - How could I find the minimum value from table with say 80columns. 

How is this table represented? Is it in a database? Is it in a flat file 
of some kind? Do you already have it in memory in some kind of data 
structure? 

The approach to this problem depends a lot on what tools you have to 
work with. 

For this, you need to describe where this data is coming from, how you 
are thinking of representing it in variables, and (most important) you 
need to show us what code you've written to solve the problem.

The date problem was a gimme, but this is a larger task with many ways 
it could be solved. You have to show us where you're starting from 
before  you can expect people to fill in the blanks for you.

> Please email your feedback to [EMAIL PROTECTED] I will truly 
> appreciate any help that you could offer.

This seems to be a typo -- all discussion should stay on the list where 
it can be of use to everyone that is trying to learn this stuff. If you 
have not already done so, please subscribe to the list so that we can 
have the conversation on the list.
 

-- 
Chris Devers

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




Extracting Directories and Sub Directories

2004-10-25 Thread Ron Smith
The following is the script:



---snip

#!/usr/bin/perl -w



use strict;

use File::Basename;





my @lines = dirname `dir /b/s`;  print "@lines\n";



---snip



The following is the input:



C:\Perl\scripts\shots\sp2\shot_1\dir.txt

C:\Perl\scripts\shots\sp2\shot_1\filename.0001.cin

C:\Perl\scripts\shots\sp2\shot_1\filename.0002.cin

C:\Perl\scripts\shots\sp2\shot_1\filename.0003.cin

C:\Perl\scripts\shots\sp2\shot_1\filename.0004.cin

C:\Perl\scripts\shots\sp2\shot_1\filename.0005.cin

C:\Perl\scripts\shots\sp2\shot_1\file_name.0001.cin

C:\Perl\scripts\shots\sp2\shot_1\file_name.0002.cin

C:\Perl\scripts\shots\sp2\shot_1\file_name.0003.cin

C:\Perl\scripts\shots\sp2\shot_1\file_name.0004.cin

C:\Perl\scripts\shots\sp2\shot_1\file_name.0005.cin

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0001.rgb

C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0002.rgb

C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0003.rgb

C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0004.rgb

C:\Perl\scripts\shots\sp2\shot_1\sub_directory\basename.0005.rgb



I would like the output to be the following:



C:\Perl\scripts\shots\sp2\shot_1<--current
directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory  <--sub
directory



'dirname' seems to only pick up the following:



C:\Perl\scripts\shots\sp2\shot_1



I also tried the following code:



---snip

#!/usr/bin/perl -w



use strict;

use File::Basename;



my @dir_contents = `dir /b/s`;

for (@dir_contents) {

my @paths = dirname $_;

print "@paths\n";



---snip



But, I get the following (truncated for our purposes):



C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory

C:\Perl\scripts\shots\sp2\shot_1\sub_directory



I've also tried a number of other things to no avail.

Does anyone have a solution to my delima?



I've also tried the following code, but, it too fills
the buffer.



#!/usr/bin/perl -w



use strict;



my (@lines, $line, @paths);

@lines = `dir /b/s`;  print @lines;

for (@lines) {

if (/\w+\.\d+(\.\w+)$/) {

$line = $`;

$line =~ s/$/\n/;

push @paths, $line;

print "@paths";

}

}





__
Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.
http://promotions.yahoo.com/new_mail 

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




Re: Extracting Directories and Sub Directories

2004-10-25 Thread Gunnar Hjalmarsson
Ron Smith wrote:

I would like the output to be the following:
C:\Perl\scripts\shots\sp2\shot_1  <--current directory
C:\Perl\scripts\shots\sp2\shot_1\sub_directory  <--sub directory
Ron,
Recently you posted a related problem, but didn't even acknowledge that 
you got several responses.
http://www.mail-archive.com/beginners%40perl.org/msg63070.html

Why are you now presenting this in a new thread as a separate problem? 
Aren't they instead as integrated as they possibly could be?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Extracting Directories and Sub Directories

2004-10-25 Thread Ron Smith
The sulution that you and others gave to the previous
problem worked out fine. I thought I sent mail
regarding that. I didn't think that this was related
to that problem; but, it is very similar. My
appologies if I'm mistaken.

TIA -- for any input you can give me.

Ron

--- Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote:

> Ron Smith wrote:
> 
> 
> 
> > I would like the output to be the following:
> > 
> > C:\Perl\scripts\shots\sp2\shot_1  <--current
> directory
> > C:\Perl\scripts\shots\sp2\shot_1\sub_directory 
> <--sub directory
> 
> Ron,
> 
> Recently you posted a related problem, but didn't
> even acknowledge that 
> you got several responses.
>
http://www.mail-archive.com/beginners%40perl.org/msg63070.html
> 
> Why are you now presenting this in a new thread as a
> separate problem? 
> Aren't they instead as integrated as they possibly
> could be?
> 
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
> 
> -- 
> To unsubscribe, e-mail:
> [EMAIL PROTECTED]
> For additional commands, e-mail:
> [EMAIL PROTECTED]
> 
> 
> 
> 
> 






__
Do you Yahoo!?
Yahoo! Mail - You care about security. So do we.
http://promotions.yahoo.com/new_mail

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




Re: problem printf

2004-10-25 Thread deny

Try to add this lines somewhere the top of the file:
use strict;
use warnings;
and report the errors, if any.
Global symbol "$md5" requires explicit package name at ./checksum.pl 
line 11.
Global symbol "@dirs" requires explicit package name at ./checksum.pl 
line 12.
Global symbol "$dir" requires explicit package name at ./checksum.pl 
line 14.

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



MySQL+foreach loop.........roy

2004-10-25 Thread Roime bin Puniran
Hi all..
 
I have a script that read some text file in the directory...All the data inside the 
text file then would be extracted into my sql, and i used foreach loop to read the 
text file, the doing some loop while data are sorted..Here is my code.


#!/usr/bin/perl 


use DBI;
use IO::Socket;

my $path = "/home/roime/flow/";
my @folder;
my $file = ".flow";

my $dbh = DBI->connect('dbi:mysql:ayam','root','');

#Prepare the insert SQL
my $rec = $dbh->prepare("INSERT INTO t_flows(ipSrc, ipDst, pktSent, bytesSent, 
startTime, endTime, srcPort, dstPort, tcpFlags, proto,   tos) VALUES ('$value1', 
'$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', 
'$value9', '$value10', '$value11')");
$rec->execute;


foreach my $file (@folder)
{
my $full_path = $path.$file;
open(FILE, $full_path)||die("Could not read file !");
my $file_contents = ;
close(FILE);

}



my $counter = 0;
@file_array = split(/ /, file_contents);

foreach (@file_array)
{   
my $value1 = @file_array[$counter];
$counter = $counter + 1;
my $value2 = @file_array[$counter];
$counter = $counter + 1;
my $value3 = @file_array[$counter];
$counter = $counter + 1;
my $value4 = @file_array[$counter];
$counter = $counter + 1;
my $value6 = @file_array[$counter];
$counter = $counter + 1;
my $value7 = @file_array[$counter];
$counter = $counter + 1;
my $value8 = @file_array[$counter];
$counter = $counter + 1;
my $value9 = @file_array[$counter];
$counter = $counter + 1;
my $value10 = @file_array[$counter];
$counter = $counter + 1;
my $value11 = @file_array[$counter]; 
$counter = $counter + 1;

}   
===

My problem is, the data from text file seems are sorted half, but it's display 
nothingI mean the range of the data are there, but the data actually disappeer

=

Below are the view of my mysql database
+++-+---+---+-+-+-+--+---+-+
| ipSrc  | ipDst  | pktSent | bytesSent | startTime | endTime | srcPort | dstPort | 
tcpFlags | proto | tos |
+++-+---+---+-+-+-+--+---+-+
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |
|||   0 | 0 | 0 |   0 |   0 |   0 |
0 | 0 |   0 |

===

Anybody have any ide about it?That 's my code have a problem?...
Thanks a lot

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]