DBI problem

2005-12-12 Thread john

Hi all-
I'm attempting to loop thru an input file,  executing a SELECT query 
with the value from each line.
The script works for the first iteration, and then gives these error 
messages:


DBD::mysql::st fetchrow_hashref failed: fetch() without execute() at 
./describe_skus.pl line 27,  line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
 line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
 line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
 line 2190.
Use of uninitialized value in print at ./describe_skus.pl line 27, 
 line 2190.


(INFILE line 2190 is the last line.)
Here's my script:

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

# purpose: To take sku numbers from a text file, "no-imgs.txt",
# and print out their database descriptions, to a separate text file, 
"need-images.txt".


open INFILE, "no-imgs.txt" or die "Input file failed to open: $!\n";
open OUTFILE, "> need-images.txt" or die "Output filehandle not open: 
$!\n";

my @nums = ;

my $dbh=DBI->connect('dbi:mysql:productdb','script','') || 
  die "Error connecting to database: $DBI::errstr\n";


my $query2 = qq{SELECT `sku`, `title`, `vendor_stock_no`, `vendor_id` 
FROM `products` WHERE `sku`=?};


for my $num (@nums) {
   last unless $num; #exit at end-of-input-file
   next if $num =~ /^\s*\t*\n$/;  # to skip over blank lines
   $num =~ s/^\s+//; # delete leading spaces
   chomp $num;
  
   my $sth2= $dbh->prepare($query2) || die "Prepare failed: 
$DBI::errstr\n";

   $sth2->execute ("$num") || die "Couldn't execute query: $DBI::errstr\n";

   while ((my $ref) = $sth2 ->fetchrow_hashref("$num")) {
   print OUTFILE "sku, \t title, \t vendor_stock_no, \t vendor_id \n",
$ref->{sku}, $ref->{title}, $ref->{vendor_stock_no}, 
$ref->{vendor_id};

   }
   $sth2->finish ();
}

$dbh->disconnect || die "Failed to disconnect\n";   
close OUTFILE or die "cannot close output file need-imgs.txt: $!";

#End

Thanks in advance for your suggestions.
John



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




RE: extracting substrings from string using regexp

2005-12-12 Thread Pant, Hridyesh
Hi Owen,
But in windows when I am trying to install Module  YAPE::Regex I am
getting below error
Can't call method "ok" on an undefined value at
> C:/Perl/site/lib/PPM/UI.pm line 881, <$__ANONIO__> line 17

Thanks&Regards
Hridyesh


-Original Message-
From: Owen Cook [mailto:[EMAIL PROTECTED] 
Sent: 13 December 2005 12:37
To: Perl Beginners
Subject: RE: extracting substrings from string using regexp



On Tue, 13 Dec 2005, Pant, Hridyesh wrote:

> Hi,
> I have successfully installed YAPE::Regex::Explain,but when I try to
run
> ant regex program I got below error 
> 
> Can't locate YAPE/Regex.pm in @INC (@INC contains:
> C:\PROGRA~1\LUCKAS~1\ENGINS~2\ C:/Perl/lib C:/Perl/site/lib .) at
> C:/Perl/site/lib/YAPE/Regex/Explain.pm line 3.
> BEGIN failed--compilation aborted at
> C:/Perl/site/lib/YAPE/Regex/Explain.pm line 3.
> Compilation failed in require at C:\PROGRA~1\LUCKAS~1\ENGINS~2\1.pl
line
> 1.
> BEGIN failed--compilation aborted at
C:\PROGRA~1\LUCKAS~1\ENGINS~2\1.pl
> line 1.
> 
> 
> So after I try to install "YAPE-Regex" module but I am getting error
> C:\Tutorial\Perl\YAPE-Regex>ppm install YAPE-Regex.ppd
> Can't call method "ok" on an undefined value at
> C:/Perl/site/lib/PPM/UI.pm line 881, <$__ANONIO__> line 17.
> 
> 
> I think this is because of it is looking for the modules which are not
> installed.so I tried this to check dependencies of this module but I
am
> getting error on this
> C:\Tutorial\Perl\YAPE-Regex>ppm tree YAPE-Regex 
> Error: No valid repositories:
> Error: 500 Can't connect to ppm.ActiveState.com:80 (Bad hostname
> 'ppm.ActiveState.com')
> Error: 500 Can't connect to ppm.ActiveState.com:80 (Bad hostname
> 'ppm.ActiveState.com')
> 
> Could anybody suggest me how can I install YAPE::regex module
> successfully.



Not sure how it works in window, but I ended up installing all 3

Module  YAPE::Regex 
Module  YAPE::Regex::Element 
Module  YAPE::Regex::Explain 


IE, YAPE::Regex::Explain didn't require YAPE::Regex


Owen


-- 
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: extracting substrings from string using regexp

2005-12-12 Thread Owen Cook

On Tue, 13 Dec 2005, Pant, Hridyesh wrote:

> Hi,
> I have successfully installed YAPE::Regex::Explain,but when I try to run
> ant regex program I got below error 
> 
> Can't locate YAPE/Regex.pm in @INC (@INC contains:
> C:\PROGRA~1\LUCKAS~1\ENGINS~2\ C:/Perl/lib C:/Perl/site/lib .) at
> C:/Perl/site/lib/YAPE/Regex/Explain.pm line 3.
> BEGIN failed--compilation aborted at
> C:/Perl/site/lib/YAPE/Regex/Explain.pm line 3.
> Compilation failed in require at C:\PROGRA~1\LUCKAS~1\ENGINS~2\1.pl line
> 1.
> BEGIN failed--compilation aborted at C:\PROGRA~1\LUCKAS~1\ENGINS~2\1.pl
> line 1.
> 
> 
> So after I try to install "YAPE-Regex" module but I am getting error
> C:\Tutorial\Perl\YAPE-Regex>ppm install YAPE-Regex.ppd
> Can't call method "ok" on an undefined value at
> C:/Perl/site/lib/PPM/UI.pm line 881, <$__ANONIO__> line 17.
> 
> 
> I think this is because of it is looking for the modules which are not
> installed.so I tried this to check dependencies of this module but I am
> getting error on this
> C:\Tutorial\Perl\YAPE-Regex>ppm tree YAPE-Regex 
> Error: No valid repositories:
> Error: 500 Can't connect to ppm.ActiveState.com:80 (Bad hostname
> 'ppm.ActiveState.com')
> Error: 500 Can't connect to ppm.ActiveState.com:80 (Bad hostname
> 'ppm.ActiveState.com')
> 
> Could anybody suggest me how can I install YAPE::regex module
> successfully.



Not sure how it works in window, but I ended up installing all 3

Module  YAPE::Regex 
Module  YAPE::Regex::Element 
Module  YAPE::Regex::Explain 


IE, YAPE::Regex::Explain didn't require YAPE::Regex


Owen


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




RE: extracting substrings from string using regexp

2005-12-12 Thread Pant, Hridyesh
Hi,
I have successfully installed YAPE::Regex::Explain,but when I try to run
ant regex program I got below error 

Can't locate YAPE/Regex.pm in @INC (@INC contains:
C:\PROGRA~1\LUCKAS~1\ENGINS~2\ C:/Perl/lib C:/Perl/site/lib .) at
C:/Perl/site/lib/YAPE/Regex/Explain.pm line 3.
BEGIN failed--compilation aborted at
C:/Perl/site/lib/YAPE/Regex/Explain.pm line 3.
Compilation failed in require at C:\PROGRA~1\LUCKAS~1\ENGINS~2\1.pl line
1.
BEGIN failed--compilation aborted at C:\PROGRA~1\LUCKAS~1\ENGINS~2\1.pl
line 1.


So after I try to install "YAPE-Regex" module but I am getting error
C:\Tutorial\Perl\YAPE-Regex>ppm install YAPE-Regex.ppd
Can't call method "ok" on an undefined value at
C:/Perl/site/lib/PPM/UI.pm line 881, <$__ANONIO__> line 17.


I think this is because of it is looking for the modules which are not
installed.so I tried this to check dependencies of this module but I am
getting error on this
C:\Tutorial\Perl\YAPE-Regex>ppm tree YAPE-Regex 
Error: No valid repositories:
Error: 500 Can't connect to ppm.ActiveState.com:80 (Bad hostname
'ppm.ActiveState.com')
Error: 500 Can't connect to ppm.ActiveState.com:80 (Bad hostname
'ppm.ActiveState.com')

Could anybody suggest me how can I install YAPE::regex module
successfully.

Thanks
Hridyesh

-Original Message-
From: Xavier Noria [mailto:[EMAIL PROTECTED] 
Sent: 13 December 2005 03:07
To: Perl Beginners
Subject: Re: extracting substrings from string using regexp


On Dec 12, 2005, at 22:10, Owen wrote:

> Xavier Noria wrote:
>> On Dec 12, 2005, at 11:10, Alexandre Checinski wrote:
>
>>> I have a string that looks like this :
>>> >> name="pcmTcuFaultOutOfService"/>
>
>>
>> m// in list contex may help:
>>
>> my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};
>
>
> I despair of ever understanding REs
>
> How does the above work
>
> m Match
> { inside these braces (as the delimiter?)
> id="  the characters   id="
> ( Start the capture for $id
> [^"]  The list of characters beginning with "
>   But wasn't that done on line 3 where we
>   looked for a  "
> * any number of characters
> ) end of capture for $id
> " the end  " for the data element captured
> .*anything until
> name="etc do it all again till
>
> } ending delimiter

Good exercise!

The answer is short, but since you already did this effort I'll tell  
you a way to figure out what's missing that's very close to your  
approach: Ask japhy's YAPE::Regex::Explain about it:

 use YAPE::Regex::Explain;
 print YAPE::Regex::Explain->new(qr{id="([^"]*)".*name="([^"]*)"/ 
 >})->explain;

-- fxn


-- 
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]
 




New lines are not removed using HTML::Strip::Whitespace module

2005-12-12 Thread Durai raj
Hi All,
   
   I tried to remove white space and newlines from HTML pages using 
HTML::Strip::Whitespace module. It removes the white space, but not NEW LINES.
  Here is my script:
   
  
 use HTML::Strip::Whitespace qw(html_strip_whitespace);
  my $html = q {
  


  
Hello there!

  
  
  };
  my $buffer = "";
  html_strip_whitespace(
'source' => \$html,
'out' => \$buffer,
'strip_newlines' => 1
);
print $buffer;

   
  Output:
   
  


Hello there!




  Instead of: 
 Hello world!
   
  Whats the problem? Is it in the script or in mopdule?
   
  Thanks in advance.
   
  Regards,
  Durai


-
Yahoo! Shopping
 Find Great Deals on Holiday Gifts at Yahoo! Shopping 

Re: sort files by creation time

2005-12-12 Thread Brian Volk

Todd W wrote:


"Brian Volk" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
 


After running a few tests... :~)  I think I might be able to sort on the
inode... ?  Does this make sense?

my @files = glob("/mnt/qdls/MSDSIN/*");

foreach my $file (@files) {

  print "$file\n";
  my $ino = (stat($file))[1];
  print "ino is $ino\n";

Thanks!

   



Bob S gave you the answer. Change the line:

my @files = glob("/mnt/qdls/MSDSIN/*");

to:

my @files = map $_->[0],
sort { $b->[1] <=> $a->[1] }
map [ $_, -M ],
grep -f, # get only plain files
glob("/mnt/qdls/MSDSIN/*");

And you are all done.

Todd W.



 

Thank you to everyone for there responses...  Great stuff!  Of course I 
have one more rookie question and a reference to a perldoc is just 
fine.  :~)  If I use the following code, why do I not need to declare 
the $a and the $b w/ my?  I searched Google and found this " but rather 
are handed to the subroutine as the values of the global variables |$a| 
and |$b|."  does this mean $a and $b are built in variables which I do 
not need to declare?


Thanks again!
-
#!/usr/bin/perl

use strict;
use warnings;

my @files = glob("c:/brian/hp_work/text/*");

  foreach my $file ( sort {(stat($b))[9] <=> (stat($a))[9]} @files) 
{  
   
  print "$file\n";


   }
--
Brian Volk



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




RE: sort files by creation time

2005-12-12 Thread Brian Volk


-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 4:44 PM
To: Brian Volk
Cc: 'beginners@perl.org'
Subject: Re: sort files by creation time

Brian Volk wrote:
> Hi All~
> 
>  
> 
> I'm using the glob function to grab all the files in a given directory
> and
> then using crontab to check it every 5 minutes.  Once I have the files
> I'm
> using the diamond operator to read every line in every file and *do
> something* if the line matches.   Here's my questions:
> 
>  
> 
> Given directory:
> 
> File 1 - in dir at 9:01
> 
> File 2 - in dir at 9:02
> 
> File 3 - in dir at 9:03
> 
>  
> 
> I would like to process the File 1 first then File 2 and then File 3.
> Each
> file contains data that I need to print for that order.  If I can
> process
> the orders (File 1, File 2, File 3) according to the time they entered
> the
> given dir (first in/first out) the data will print off in the correct
> sequence.  

This will load @ARGV with the files in the current directory sorted 
oldest -> newest:

   @ARGV = map $_->[0],
 sort { $b->[1] <=> $a->[1] }
 map [ $_, -M ],
 grep -f, # get only plain files
 <*>;

How it works is left as an exercise for the reader :-)

Thank you!  And I think I just bought the book that explains the above!
Alpaca! Soon to find out! 

Thanks again.

Brian Volk

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




Satya Sai is out of the office.

2005-12-12 Thread Satya_Sai

I will be out of the office starting  12/12/2005 and will not return until
12/19/2005.

I will respond to your message when I return.  Please contact
[EMAIL PROTECTED] or call DBA Hotline at 4477 for DBA assisstance.


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




RE: sort files by creation time

2005-12-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Brian Volk wrote:
> Hi All~
> 
> 
> 
> I'm using the glob function to grab all the files in a given
> directory and then using crontab to check it every 5 minutes.  Once I
> have the files I'm using the diamond operator to read every line in
> every file and *do something* if the line matches.   Here's my
> questions: 
> 
> 
> 
> Given directory:
> 
> File 1 - in dir at 9:01
> 
> File 2 - in dir at 9:02
> 
> File 3 - in dir at 9:03
> 
> 
> 
> I would like to process the File 1 first then File 2 and then File 3.
> Each file contains data that I need to print for that order.  If I
> can process the orders (File 1, File 2, File 3) according to the time
> they entered the given dir (first in/first out) the data will print
> off in the correct sequence.
> 
> 
> 
> Is there a module I can use for this?  Maybe File::Stat?  Or can I do
> a sort of some kind right after the while <> ?
> 
> 
> 
> Can someone pls let me know what function I'm supposed to use or which
> module I need.
> 
> 
> 
> Thanks!!!
> 
> 
> 
> 
> 
> 
> 
> Below is some of the code:
> 
> 
> 
> I'm using the code below to check if there are any files in the dir. 
> If so, then goto to the PMSDS sub.
> 
> 
> 
> my @files = glob("/home/bvolk/test_msds_in/*");
> 
> 
> 
>   my $count = ();
> 
>   foreach my $file (@files) {
Replace above line with:
foreach my $file ( sort {(stat($a))[9] <=> (stat($b))[9]} 
@files)
This wwill sort oldest file to newest. Change the a and b around for newest to 
oldest.

Wags ;)
> 
>  $count++;
> 
>  if ($count > 0) {
> 
>  &PMSDS;
> 
> last;
> 
> 
>}
> 
>   }
> 
> 
> 
> 
> 
> -some of the  PMSDS sub
> 
> 
> 
> @ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;
> 
> 
> 
>  my %DIR_LIST;
> 
> 
> 
>  $DIR_LIST{$_} = 1 for @pdfs;
> 
> 
> 
> while (<>) {
> 
>   chomp;
> 
>   $_ =~ s/\s+\z//;
> 
> 
> 
> if(exists($DIR_LIST{$_})){
> 
> my   $basename = fileparse($ARGV,'.TXT');
> 
>   $basename =~ s/O//;
> 
>   $_ =~ s/.pdf//i;
> 
> 
> 
>   print "Job $basename printing msds $_\n";
> 
>   } else {
> 
>   my $basename = fileparse($ARGV,'.TXT');
> 
>   $basename =~ s/O//;
> 
>   print "Job $basename missing  msds $_\n"
> 
> 
> 
> }
> 
>   }
> 
> 
> 
> 
> 
> brian volk
> 
> hpproducts.com
> 
> [EMAIL PROTECTED] 
> 
> 317-298-9950 x1245



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


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




Re: sort files by creation time

2005-12-12 Thread Todd W

"Brian Volk" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> After running a few tests... :~)  I think I might be able to sort on the
> inode... ?  Does this make sense?
>
> my @files = glob("/mnt/qdls/MSDSIN/*");
>
> foreach my $file (@files) {
>
>print "$file\n";
>my $ino = (stat($file))[1];
>print "ino is $ino\n";
>
> Thanks!
>

Bob S gave you the answer. Change the line:

my @files = glob("/mnt/qdls/MSDSIN/*");

to:

my @files = map $_->[0],
 sort { $b->[1] <=> $a->[1] }
 map [ $_, -M ],
 grep -f, # get only plain files
 glob("/mnt/qdls/MSDSIN/*");

And you are all done.

Todd W.



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




Re: extracting substrings from string using regexp

2005-12-12 Thread Owen Cook

On Mon, 12 Dec 2005, Xavier Noria wrote:

> On Dec 12, 2005, at 22:10, Owen wrote:
> 
> > Xavier Noria wrote:
> >> On Dec 12, 2005, at 11:10, Alexandre Checinski wrote:
> >
> >>> I have a string that looks like this :
> >>>  >>> name="pcmTcuFaultOutOfService"/>
> >
> >>
> >> m// in list contex may help:
> >>
> >> my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};

> The answer is short, but since you already did this effort I'll tell  
> you a way to figure out what's missing that's very close to your  
> approach: Ask japhy's YAPE::Regex::Explain about it:
> 
>  use YAPE::Regex::Explain;
>  print YAPE::Regex::Explain->new(qr{id="([^"]*)".*name="([^"]*)"/ 
>  >})->explain;


Thank you for bring that module to my attention, it is truely
instructional.

It says of

   [^"]* any character except: '"' (0 or more
 times (matching the most amount possible))


So having now read the appropriate section in my Programming Perl, I
see "A caret in front of a list causes it match only characters that are
NOT in the list"

Thank you



Owen


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




RE: sort files by creation time

2005-12-12 Thread Ryan Frantz


> -Original Message-
> From: Brian Volk [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 12, 2005 4:47 PM
> To: beginners@perl.org
> Subject: RE: sort files by creation time
> 
> After running a few tests... :~)  I think I might be able to sort on
the
> inode... ?  Does this make sense?
> 
> my @files = glob("/mnt/qdls/MSDSIN/*");
> 
>   foreach my $file (@files) {
> 
>  print "$file\n";
>  my $ino = (stat($file))[1];
>  print "ino is $ino\n";

Looks like you're on the right track with the stat function, but you
probably don't want to sort by the inode.  A higher inode doesn't
necessarily mean that a file was created later (think about deleted
files).  Keep reading up on stat...

ry

> 
> Thanks!
> 
> Brian
> 
> -Original Message-
> From: Brian Volk [mailto:[EMAIL PROTECTED]
> Sent: Monday, December 12, 2005 12:33 PM
> To: 'beginners@perl.org'
> Subject: sort files by creation time
> 
> Hi All~
> 
> 
> 
> I'm using the glob function to grab all the files in a given directory
and
> then using crontab to check it every 5 minutes.  Once I have the files
I'm
> using the diamond operator to read every line in every file and *do
> something* if the line matches.   Here's my questions:
> 
> 
> 
> Given directory:
> 
> File 1 - in dir at 9:01
> 
> File 2 - in dir at 9:02
> 
> File 3 - in dir at 9:03
> 
> 
> 
> I would like to process the File 1 first then File 2 and then File 3.
> Each
> file contains data that I need to print for that order.  If I can
process
> the orders (File 1, File 2, File 3) according to the time they entered
the
> given dir (first in/first out) the data will print off in the correct
> sequence.
> 
> 
> 
> Is there a module I can use for this?  Maybe File::Stat?  Or can I do
a
> sort
> of some kind right after the while <> ?
> 
> 
> 
> Can someone pls let me know what function I'm supposed to use or which
> module I need.
> 
> 
> 
> Thanks!!!
> 
> 
> 
> 
> 
> 
> 
> Below is some of the code:
> 
> 
> 
> I'm using the code below to check if there are any files in the dir.
If
> so,
> then goto to the PMSDS sub.
> 
> 
> 
> my @files = glob("/home/bvolk/test_msds_in/*");
> 
> 
> 
>   my $count = ();
> 
>   foreach my $file (@files) {
> 
>  $count++;
> 
>  if ($count > 0) {
> 
>  &PMSDS;
> 
> last;
> 
> 
>}
> 
>   }
> 
> 
> 
> 
> 
> -some of the  PMSDS sub
> 
> 
> 
> @ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;
> 
> 
> 
>  my %DIR_LIST;
> 
> 
> 
>  $DIR_LIST{$_} = 1 for @pdfs;
> 
> 
> 
> while (<>) {
> 
>   chomp;
> 
>   $_ =~ s/\s+\z//;
> 
> 
> 
> if(exists($DIR_LIST{$_})){
> 
> my   $basename = fileparse($ARGV,'.TXT');
> 
>   $basename =~ s/O//;
> 
>   $_ =~ s/.pdf//i;
> 
> 
> 
>   print "Job $basename printing msds $_\n";
> 
>   } else {
> 
>   my $basename = fileparse($ARGV,'.TXT');
> 
>   $basename =~ s/O//;
> 
>   print "Job $basename missing  msds $_\n"
> 
> 
> 
> }
> 
>   }
> 
> 
> 
> 
> 
> brian volk
> 
> hpproducts.com
> 
> [EMAIL PROTECTED] 
> 
> 317-298-9950 x1245
> 
> 
> 
> 
> 
> --
> 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: sort files by creation time

2005-12-12 Thread Timothy Johnson

You could try something along these lines, where I create an array
prepending the date in Perl time format and then sort the array.  There
is probably a better way, but this would work.

Note:  (stat $file)[9] is a list slice that represents only the 9th
element of the list returned by 'stat $file'. Check out 'perldoc -f
stat'


###

use strict;
use warnings;

opendir(DIR,".") or die("Couldn't open '.'!");
my @files = readdir(DIR);

foreach my $file(@files){
#prepend the modified time
$file = (stat $file)[9].'#'.$file;
}

foreach my $sorted_file(sort @files){
#strip out the modified time so we're left with the file name
$sorted_file =~ s/^\d+\#//;
print "".localtime((stat $sorted_file)[9])." => $sorted_file\n";
}



-Original Message-
From: Brian Volk [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 9:33 AM
To: 'beginners@perl.org'
Subject: sort files by creation time

Hi All~



I would like to process the File 1 first then File 2 and then File 3.
Each
file contains data that I need to print for that order.  If I can
process
the orders (File 1, File 2, File 3) according to the time they entered
the
given dir (first in/first out) the data will print off in the correct
sequence.  




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




Re: convert string from lowercase to uppercase

2005-12-12 Thread John Doe
Buehler, Bob am Montag, 12. Dezember 2005 22.18:
> Also:
>
> $name =~ tr/a-z/A-Z/;
>
> (the string is in $name variable)

Ok, but this won't match words in my language (and others) or words containing 
unicode.

:-)


> -Original Message-
> From: John Doe [mailto:[EMAIL PROTECTED]
[...]
> Jenny Chen am Montag, 12. Dezember 2005 21.49:
> > Hi All,
[...]
> > Does anyone know how to convert a string in lower case
> > to upper case in Perl?  Thanks.
>
> yes,
>
> perldoc -f uc
>
> does.
>
> hth, joe

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




Re: extracting substrings from string using regexp

2005-12-12 Thread John Doe
Owen am Montag, 12. Dezember 2005 22.10:
> Xavier Noria wrote:
> > On Dec 12, 2005, at 11:10, Alexandre Checinski wrote:
> >> I have a string that looks like this :
> >>  >> name="pcmTcuFaultOutOfService"/>
> >
> > m// in list contex may help:
> >
> > my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};
>
> I despair of ever understanding REs

You will, just play around with it:

for example, make a "quick and dirty" small script along the lines

=start=

use strict;
use warnings;

my $teststring='something to test';

my $ok=$teststring=~m~sts~; # <<< play around here

print $ok ? 'yes, I got it!!!' : 'I despair of ever understanding REs';

=end=

If you think a regex does something, test the something with above script.
keep open some manuals:
perldoc perlre
perldoc perlretut
perldoc perlrequick

>
> How does the above work
>
> m Match
> { inside these braces (as the delimiter?)

No; the {} are in place of the usual //. That's why the 'm' after '=~' is 
mandatory. Same holds for substitution. Sometimes the regexes are more 
readable if somethings else than '//' is used, for example when matching 
(unix) paths.

> id="  the characters   id="
> ( Start the capture for $id
> [^"]  The list of characters beginning with "

Not exactly; The list of chars *not* matching '"', thus the caret just after 
'['.

>   But wasn't that done on line 3 where we
>   looked for a  "
> * any number of characters

(including none)

> ) end of capture for $id
> " the end  " for the data element captured
> .*anything until

more precicely: nothing or anything in "greedy"-mode until

> name="etc do it all again till
>
> } ending delimiter
>
> So I have trouble with [^"]*

This means: none or more characters not being a '"'.

>
> What words describe that expression please

my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};

Extract two values $id and $name from the string $xml.

Do that by searching the literal string 'id="';
then look for someting between two doublequotes, whereby the thing between 
must not contain a doublequote, and catch it into $1;
then skip everything until the literal string 'name=';
then look for someting between two doublequotes, whereby the thing between 
must not contain a doublequote, and catch it into $2;
then match a directly following literal string '/>'.
Finally, assign ($1, $2) to the list ($id, $name).

The regex could be improved a bit, I think:

1. it would be less restrictive to allow spaces around '=' and before '/>'
2. there is a problem with the '.*' in the middle: if there are several tags 
containing a name attribute, it will match the 'name=' of the last tag 
containing a name attribute. This is because '.*' is greedy.
3. I'm not sure, but I think there must be a space between an attribute value   
and the next attribute name

This leads to

m{id\s*=\s*"([^"]*)".+?name\s*=\s*"([^"]*)"\s*/>};

But even this version could be improved 
(f.e. it can't handle escaped doublequotes (\") within the 
attribute values. I'm not sure, but I think this is not allowed, but could be 
used to trick the regex doing the wrong thing)

Somebody please correct me if I'm wrong, thanks, I'm overworked (beside not 
being a guru)

hth, joe


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




RE: sort files by creation time

2005-12-12 Thread Brian Volk
After running a few tests... :~)  I think I might be able to sort on the
inode... ?  Does this make sense? 

my @files = glob("/mnt/qdls/MSDSIN/*");

foreach my $file (@files) {
 
   print "$file\n";
   my $ino = (stat($file))[1];
   print "ino is $ino\n";

Thanks!

Brian 

-Original Message-
From: Brian Volk [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 12:33 PM
To: 'beginners@perl.org'
Subject: sort files by creation time

Hi All~

 

I'm using the glob function to grab all the files in a given directory and
then using crontab to check it every 5 minutes.  Once I have the files I'm
using the diamond operator to read every line in every file and *do
something* if the line matches.   Here's my questions:

 

Given directory:

File 1 - in dir at 9:01

File 2 - in dir at 9:02

File 3 - in dir at 9:03

 

I would like to process the File 1 first then File 2 and then File 3.  Each
file contains data that I need to print for that order.  If I can process
the orders (File 1, File 2, File 3) according to the time they entered the
given dir (first in/first out) the data will print off in the correct
sequence.  

 

Is there a module I can use for this?  Maybe File::Stat?  Or can I do a sort
of some kind right after the while <> ?

 

Can someone pls let me know what function I'm supposed to use or which
module I need.

 

Thanks!!!

 

 

 

Below is some of the code: 

 

I'm using the code below to check if there are any files in the dir.  If so,
then goto to the PMSDS sub. 

 

my @files = glob("/home/bvolk/test_msds_in/*");

 

  my $count = ();

  foreach my $file (@files) {   

 $count++;

 if ($count > 0) {

 &PMSDS;

last;


   }

  }

 

 

-some of the  PMSDS sub 

 

@ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;

 

 my %DIR_LIST;

 

 $DIR_LIST{$_} = 1 for @pdfs;

 

while (<>) {

  chomp;

  $_ =~ s/\s+\z//;

  

if(exists($DIR_LIST{$_})){ 

my   $basename = fileparse($ARGV,'.TXT');

  $basename =~ s/O//;

  $_ =~ s/.pdf//i;

 

  print "Job $basename printing msds $_\n";

  } else {

  my $basename = fileparse($ARGV,'.TXT');

  $basename =~ s/O//;

  print "Job $basename missing  msds $_\n"

  

}

  }

 

 

brian volk

hpproducts.com

[EMAIL PROTECTED]  

317-298-9950 x1245

 



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




Re: sort files by creation time

2005-12-12 Thread Bob Showalter

Brian Volk wrote:

Hi All~

 


I'm using the glob function to grab all the files in a given directory
and
then using crontab to check it every 5 minutes.  Once I have the files
I'm
using the diamond operator to read every line in every file and *do
something* if the line matches.   Here's my questions:

 


Given directory:

File 1 - in dir at 9:01

File 2 - in dir at 9:02

File 3 - in dir at 9:03

 


I would like to process the File 1 first then File 2 and then File 3.
Each
file contains data that I need to print for that order.  If I can
process
the orders (File 1, File 2, File 3) according to the time they entered
the
given dir (first in/first out) the data will print off in the correct
sequence.  


This will load @ARGV with the files in the current directory sorted 
oldest -> newest:


  @ARGV = map $_->[0],
sort { $b->[1] <=> $a->[1] }
map [ $_, -M ],
grep -f, # get only plain files
<*>;

How it works is left as an exercise for the reader :-)

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




Re: extracting substrings from string using regexp

2005-12-12 Thread Xavier Noria

On Dec 12, 2005, at 22:10, Owen wrote:


Xavier Noria wrote:

On Dec 12, 2005, at 11:10, Alexandre Checinski wrote:



I have a string that looks like this :





m// in list contex may help:

my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};



I despair of ever understanding REs

How does the above work

m   Match
{   inside these braces (as the delimiter?)
id="   the characters   id="
(   Start the capture for $id
[^"]   The list of characters beginning with "
But wasn't that done on line 3 where we
looked for a  "
*   any number of characters
)   end of capture for $id
"  the end  " for the data element captured
.*  anything until
name=" etc do it all again till

}   ending delimiter


Good exercise!

The answer is short, but since you already did this effort I'll tell  
you a way to figure out what's missing that's very close to your  
approach: Ask japhy's YAPE::Regex::Explain about it:


use YAPE::Regex::Explain;
print YAPE::Regex::Explain->new(qr{id="([^"]*)".*name="([^"]*)"/ 
>})->explain;


-- fxn


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




sort files by creation time

2005-12-12 Thread Brian Volk
Hi All~

 

I'm using the glob function to grab all the files in a given directory and
then using crontab to check it every 5 minutes.  Once I have the files I'm
using the diamond operator to read every line in every file and *do
something* if the line matches.   Here's my questions:

 

Given directory:

File 1 - in dir at 9:01

File 2 - in dir at 9:02

File 3 - in dir at 9:03

 

I would like to process the File 1 first then File 2 and then File 3.  Each
file contains data that I need to print for that order.  If I can process
the orders (File 1, File 2, File 3) according to the time they entered the
given dir (first in/first out) the data will print off in the correct
sequence.  

 

Is there a module I can use for this?  Maybe File::Stat?  Or can I do a sort
of some kind right after the while <> ?

 

Can someone pls let me know what function I'm supposed to use or which
module I need.

 

Thanks!!!

 

 

 

Below is some of the code: 

 

I'm using the code below to check if there are any files in the dir.  If so,
then goto to the PMSDS sub. 

 

my @files = glob("/home/bvolk/test_msds_in/*");

 

  my $count = ();

  foreach my $file (@files) {   

 $count++;

 if ($count > 0) {

 &PMSDS;

last;


   }

  }

 

 

-some of the  PMSDS sub 

 

@ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS;

 

 my %DIR_LIST;

 

 $DIR_LIST{$_} = 1 for @pdfs;

 

while (<>) {

  chomp;

  $_ =~ s/\s+\z//;

  

if(exists($DIR_LIST{$_})){ 

my   $basename = fileparse($ARGV,'.TXT');

  $basename =~ s/O//;

  $_ =~ s/.pdf//i;

 

  print "Job $basename printing msds $_\n";

  } else {

  my $basename = fileparse($ARGV,'.TXT');

  $basename =~ s/O//;

  print "Job $basename missing  msds $_\n"

  

}

  }

 

 

brian volk

hpproducts.com

[EMAIL PROTECTED]  

317-298-9950 x1245

 



RE: convert string from lowercase to uppercase

2005-12-12 Thread Buehler, Bob
Also:

$name =~ tr/a-z/A-Z/;

(the string is in $name variable)

-Original Message-
From: John Doe [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 3:02 PM
To: beginners@perl.org
Subject: Re: convert string from lowercase to uppercase


Jenny Chen am Montag, 12. Dezember 2005 21.49:
> Hi All,

Hi

> Does anyone know how to convert a string in lower case
> to upper case in Perl?  Thanks.

yes,

perldoc -f uc 

does.

hth, joe

-- 
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: convert string from lowercase to uppercase

2005-12-12 Thread Chris Devers
On Mon, 12 Dec 2005, Jenny Chen wrote:

> Does anyone know how to convert a string in lower case
> to upper case in Perl?  Thanks.
 
Undoubtedly.

How did you try to do it ?

Did you try the s/// substitution feature ?
perldoc -f s 

Did you try the tr/// transliteration operator ? 
perldoc -f tr

Did you try the uc() uppercase command ? 
perldoc -f uc

uc() is probably the one you want, but the others offer more flexibility 
and can be preferable in certain contexts. 




-- 
Chris Devers

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




Re: extracting substrings from string using regexp

2005-12-12 Thread Owen
Xavier Noria wrote:
> On Dec 12, 2005, at 11:10, Alexandre Checinski wrote:

>> I have a string that looks like this :
>> > name="pcmTcuFaultOutOfService"/>

> 
> m// in list contex may help:
> 
> my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};


I despair of ever understanding REs

How does the above work

m   Match
{   inside these braces (as the delimiter?)
id="the characters   id="
(   Start the capture for $id
[^"]The list of characters beginning with "
But wasn't that done on line 3 where we
looked for a  "
*   any number of characters
)   end of capture for $id
"   the end  " for the data element captured
.*  anything until
name="  etc do it all again till

}   ending delimiter

So I have trouble with [^"]*

What words describe that expression please

TIA


Owen

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




Re: convert string from lowercase to uppercase

2005-12-12 Thread John Doe
Jenny Chen am Montag, 12. Dezember 2005 21.49:
> Hi All,

Hi

> Does anyone know how to convert a string in lower case
> to upper case in Perl?  Thanks.

yes,

perldoc -f uc 

does.

hth, joe

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




convert string from lowercase to uppercase

2005-12-12 Thread Jenny Chen
Hi All,

Does anyone know how to convert a string in lower case
to upper case in Perl?  Thanks.

Jenny

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




Simple Ithread test

2005-12-12 Thread Venkatesan Saranathan
Hi List,

I am trying to create a very simple program using Perl threads. My
test program accepts list of host names from command line, creates a
separate thread for each host name and within the thread, it pings the
given host and stores the result in a shared hash.   But this is
giving unpredictable results so far.  It seems to be working fine on
Windows 2000 but not on Windows XP.

Any ideas?  I am using ActivePerl 5.8.7.

The program listing is given below.

#!/bin/perl -w
#

use strict;
use threads;
use threads::shared;

use Net::Ping;

# Mark this hash sharable by all threads.
my %status : shared;

my $MAX_THREADS = 20;

main();

# returns the total number of threads in the threads list.
sub get_thread_count {
   my (@threads);
   return(scalar(@threads = threads->list));
}

# if the current number of threads is equal to/greater than the
# predefined limit, then releases the completed threads until the
# running threads becomes less than the maximum limit for threads.
sub wait_for_threads {
   my ($thread_count) = @_;
   my (@thread_list, $thread);
   @thread_list = threads->list;

   while (get_thread_count() >= $thread_count) {
   $thread = shift(@thread_list);
   if ($thread->tid && !threads::equal($thread, threads->self)) {
   $thread->join;
   }
   }
}

sub main {
   my ($thread, $host);
   while (<>) {
   chomp;
   threads->new(\&ping_host, $_);

   if (get_thread_count() >= $MAX_THREADS) {
   print "Max thread limit reached: ", get_thread_count(), "\n";
   wait_for_threads($MAX_THREADS - 10);
   }
   }

   # wait for all the currently running threads to finish.
   foreach $thread (threads->list) {
   # Main thread has a thread id of zero. Skip the main thread
   # and this thread while joining.
   if ($thread->tid && !threads::equal($thread, threads->self)) {
   $thread->join;
   }
   }

   # at this point, all the threads have finished and the result is
   # in the hash.  Print the status by looping thru the keys.
   foreach $host (sort keys %status) {
   print "$host is $status{$host}.\n";
   }
}

sub ping_host {
   use Net::Ping;
   my ($host) = @_;
   my ($p, $result);

   $p = Net::Ping->new();
   $result = ($p->ping($host)) ? "alive" : "unreachable";
   $p->close();

   # good idea to lock the hash before making modification
   lock(%status);

   $status{$host} = $result;
}

Thanks,

with warm regards,
Venkat Saranathan.

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




Re: extracting substrings from string using regexp

2005-12-12 Thread Shawn Corey

Ing. Branislav Gerzo wrote:

you should learn regexpes, they are very powerful.
perldoc perlre


See also:
  perldoc perlrequick Perl regular expressions quick start
  perldoc perlretut   Perl regular expressions tutorial


--

Just my 0.0002 million dollars worth,
   --- Shawn

"Probability is now one. Any problems that are left are your own."
   SS Heart of Gold, _The Hitchhiker's Guide to the Galaxy_

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




modules for mail lists

2005-12-12 Thread Ing. Branislav Gerzo
Hello all,

on web page I want to have subscribers for emails (there will be rss
export too...), what is new, and so on.

So I think, it would be nice to use some mail list manager.
In DB I have emails, where to send, I will create message, use local
SMTP and so on.
But problem is with undeliverable mails - for example, when mail come
back 3 times, I'd like to disable sending mail to this address.

I take a look on CPAN and searchnig some modules for this and found:
http://search.cpan.org/~jimt/Mail-Bulkmail-3.12/Bulkmail.pm

but I didnt find nowhere how to filter undeliverable addresses.

If exists some module for this, just tell.

Thanks.


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




Re: Problem with foreach

2005-12-12 Thread John W. Krahn
Andrej Kastrin wrote:
> John W. Krahn wrote:
> 
>> Andrej Kastrin wrote:
>>> 
>>> I want to count words in the following file:
>>> --
>>> ID- some number
>>> TI- some text BB
>>> AB- some text A BB
>>> AU- some text
>>>
>>> ID- some number
>>> TI- some GGG text
>>> AB- some text GGG
>>> AU- some text
>>>
>>> ID- some number
>>> TI- some text
>>> AB- some text Z
>>> AU- some text
>>> --
>>>
>>> I wrote the script which parses througt the file and return the total
>>> number of words, defined in @list. Here is the problem. There could be
>>> more then one equal word in each record (see the first record where BB
>>> occurs twice).
>>>
>>> I don't know, how to modify my code; so if there are multiple same words
>>> in a record, frequency of each word per record does not exceed 1.
>>
>>
>> The value of $/ starts out at "\n", in other words, read one "line" at
>> a time.
>>
>>> while (<>){
>>> $/="\n\n"; #set input separator to read record
>>> $/="\n"; #set input separator to parse within a record
>>
>> You change $/ and then change it back to the default so in effect you
>> are not
>> really changing $/ at all.
>>
>>> chomp;
>>
>> chomp() is not really needed.
>>
>>> if(/^TI.+/){
>>
>> You are only modifying $wds for lines that begin with the string 'TI'
>> so the
>> 'BB' on the line beginning with 'AB' will not be counted.
>>
>>>   foreach $w (split){
>>>  $wds++ if defined($words{$w})
>>>   }
>>> }
>>> }
>>>
>>> print "\n$wds words"; #print frequency of words, defined in @list
>>
> OK, I realize, but problem still persist. How to modify my code that if
> there are 2 or more same words in one record (or in one line) only one
> is counted.

If I understand your requirements correctly, you probably want something like
this (UNTESTED):

my @list = qw( A BB GGG Z ); #define term list

$/ = ''; #set input separator to paragraph mode
my $wds;
while ( <> ) {
for my $w ( @list ) {
$wds++ if /^TI.*?\s$w\s/m;
}
}

print "\n$wds words"; #print frequency of words, defined in @list




John
-- 
use Perl;
program
fulfillment

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




Re: Problem with foreach

2005-12-12 Thread Andrej Kastrin

John W. Krahn wrote:


Andrej Kastrin wrote:
 


Hello dears,
   



Hello,

 


I want to count words in the following file:
--
ID- some number
TI- some text BB
AB- some text A BB
AU- some text

ID- some number
TI- some GGG text
AB- some text GGG
AU- some text

ID- some number
TI- some text
AB- some text Z
AU- some text
--

I wrote the script which parses througt the file and return the total
number of words, defined in @list. Here is the problem. There could be
more then one equal word in each record (see the first record where BB
occurs twice).

I don't know, how to modify my code; so if there are multiple same words
in a record, frequency of each word per record does not exceed 1.
   




The value of $/ starts out at "\n", in other words, read one "line" at a time.

 


while (<>){
$/="\n\n"; #set input separator to read record
$/="\n"; #set input separator to parse within a record
   



You change $/ and then change it back to the default so in effect you are not
really changing $/ at all.

 


chomp;
   



chomp() is not really needed.

 


if(/^TI.+/){
   



You are only modifying $wds for lines that begin with the string 'TI' so the
'BB' on the line beginning with 'AB' will not be counted.

 


  foreach $w (split){
 $wds++ if defined($words{$w})
  }
}
}

print "\n$wds words"; #print frequency of words, defined in @list
   




John
 

OK, I realize, but problem still persist. How to modify my code that if 
there are 2 or more same words in one record (or in one line) only one 
is counted.



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




Re: Problem with foreach

2005-12-12 Thread John W. Krahn
Andrej Kastrin wrote:
> Hello dears,

Hello,

> I want to count words in the following file:
> --
> ID- some number
> TI- some text BB
> AB- some text A BB
> AU- some text
> 
> ID- some number
> TI- some GGG text
> AB- some text GGG
> AU- some text
> 
> ID- some number
> TI- some text
> AB- some text Z
> AU- some text
> --
> 
> I wrote the script which parses througt the file and return the total
> number of words, defined in @list. Here is the problem. There could be
> more then one equal word in each record (see the first record where BB
> occurs twice).
> 
> I don't know, how to modify my code; so if there are multiple same words
> in a record, frequency of each word per record does not exceed 1.


The value of $/ starts out at "\n", in other words, read one "line" at a time.

> while (<>){
>  $/="\n\n"; #set input separator to read record
>  $/="\n"; #set input separator to parse within a record

You change $/ and then change it back to the default so in effect you are not
really changing $/ at all.

>  chomp;

chomp() is not really needed.

>  if(/^TI.+/){

You are only modifying $wds for lines that begin with the string 'TI' so the
'BB' on the line beginning with 'AB' will not be counted.

>foreach $w (split){
>   $wds++ if defined($words{$w})
>}
>  }
> }
> 
> print "\n$wds words"; #print frequency of words, defined in @list


John
-- 
use Perl;
program
fulfillment

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




Re: extracting substrings from string using regexp

2005-12-12 Thread Xavier Noria

On Dec 12, 2005, at 11:10, Alexandre Checinski wrote:


hello everyone,
I have a simple question.
I have a string that looks like this :
name="pcmTcuFaultOutOfService"/>
and I would like to store the values for id and name in two  
different variables.

I know how to do it using regexp.
But the way I do it is done using several lines of code.


m// in list contex may help:

my ($id, $name) = $xml =~ m{id="([^"]*)".*name="([^"]*)"/>};

But consider using a XML parser if you need something more robust.

-- fxn


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




Re: extracting substrings from string using regexp

2005-12-12 Thread Ing. Branislav Gerzo
Alexandre Checinski [AC], on Monday, December 12, 2005 at 11:10
(+0100) wrote:

from head:

my $string = '';
my ($id, $name) = $string =~ /id="(\d+)".*?name="([^"]+)"/;

AC> PS: I'm a total newbie...

you should learn regexpes, they are very powerful.
perldoc perlre

For parsing XMl files use some XMl parser.

-- 

How do you protect mail on web? I use http://www.2pu.net

[Kazon Borg: "We have assimilated an enemy today!"]



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




extracting substrings from string using regexp

2005-12-12 Thread Alexandre Checinski

hello everyone,
I have a simple question.
I have a string that looks like this :
name="pcmTcuFaultOutOfService"/>
and I would like to store the values for id and name in two different 
variables.

I know how to do it using regexp.
But the way I do it is done using several lines of code.
I'm sure there's a way to do it with one line.
Does anyone have an idea on ow to do it?

Thx

PS: I'm a total newbie...

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




Problem with foreach

2005-12-12 Thread Andrej Kastrin

Hello dears,

I want to count words in the following file:
--
ID- some number
TI- some text BB
AB- some text A BB
AU- some text

ID- some number
TI- some GGG text
AB- some text GGG
AU- some text

ID- some number
TI- some text
AB- some text Z
AU- some text
--

I wrote the script which parses througt the file and return the total 
number of words, defined in @list. Here is the problem. There could be 
more then one equal word in each record (see the first record where BB 
occurs twice).


I don't know, how to modify my code; so if there are multiple same words 
in a record, frequency of each word per record does not exceed 1.


Best, Andrej

while (<>){
 $/="\n\n"; #set input separator to read record
 $/="\n"; #set input separator to parse within a record
 chomp;
 if(/^TI.+/){
   foreach $w (split){
  $wds++ if defined($words{$w})
   }
 }
}

print "\n$wds words"; #print frequency of words, defined in @list




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




Re: Input separator and block problem

2005-12-12 Thread Andrej Kastrin

Andrej Kastrin wrote:


Hi

I want to count words in the following file:
--
ID- some number
TI- some text BB
AB- some text
AU- some text

ID- some number
TI- some GGG text
AB- some text
AU- some text

ID- some number
TI- some text
AB- some text Z
AU- some text
--
So, the separators between records are blank lines ("\n\n"). I wrote 
script, which count wods, which are defined in the @list array. So, I 
need frequency of (A, BB, GGG and Z) in the lines, which begind with 
TI (or AB or AU, but this is not problem at the moment).And here is 
the catch, while TI is not at the beginning of each record!!!


-
@list = qw(A BB GGG Z); #define term list
foreach $member(@list){
 $words{$member}=0;  #create hash form array
}

{ # begin block
$/="\n\n"; #set input separator to 1 blank line
while (<>){
 chomp;
   if(/^TI.+/){
   foreach $w (split){
 $wds++ if defined($words{$w})
   }
 }
 }

} #end block
print "\n$wds words"; #print frequency of words, defined in @list


How to proceed? Thanks in advance, Andrej


Me, again. I modify it in the following way: look below the while 
statement. Is that OK? (It's working btw.).


-
@list = qw(A BB GGG Z); #define term list
foreach $member(@list){
$words{$member}=0;  #create hash form array
}

while (<>){
  $/="\n\n"; #set input separator to read record
  $/="\n"; #set input separator to parse within a record
  chomp;
  if(/^TI.+/){
foreach $w (split){
   $wds++ if defined($words{$w})
}
  }
}

print "\n$wds words"; #print frequency of words, defined in @list



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