Re: how to append blocks in same file

2005-06-23 Thread John W. Krahn

Aditi Gupta wrote:

Hi Perlers,


Hello,


I have a file as follows:

#block1
aaa
aaa

#block2
bbb
bbb

#block3
ccc
ccc

and i want to append(or i should say merge) these blocks and get a file like 
this:


aaabbbccc
aaabbbccc

how can this be done using perl?
please help..



$ echo 
aaa
aaa

bbb
bbb

ccc
ccc
 | perl -l -00ne'my $i; $x[ $i++ ] .= $_ for split /\n/ }{ print for @x'
aaabbbccc
aaabbbccc



John
--
use Perl;
program
fulfillment

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




Re: Critcize my scripts.

2005-06-23 Thread John W. Krahn

loan tran wrote:

Please critize my scripts and suggest better ways to
accomplish the same task. 


(I know it's a good practice to put use strict in Perl
script but I'm struggling to make my scripts work with
use strict.The script below work fine if I comment out
use strict.)


They look more like shell scripts than Perl programs.

Don't use qx() for everything, use Perl's built-in operators/functions or if 
you have to, use system().


perldoc perlop
perldoc perlfunc

Don't use an ampersand in front of function names.

perldoc perlsub


John
--
use Perl;
program
fulfillment

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




Re: finding needle in a haystack

2005-06-23 Thread Ing. Branislav Gerzo
Chris Devers [CD], on Wednesday, June 22, 2005 at 17:53 (-0400 (EDT))
wrote the following:

CD   my $fields = split( /\s+/, $record );
CD   my $fourth = $fields[3];
CD This problem doesn't require any looping! :-)

I, know, thats just example.

I read whole the message, in original was:
I want to read in one record at a time, that has space-delimited
fields.

Also I think, author will need 2-nd, and n-th word, so maybe he
found my example useful. Also perl is about
not only 1 way is correct:)...but we know that.

-- 

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

[Wish to our future on a far away star.]



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




Re: finding needle in a haystack

2005-06-23 Thread Ing. Branislav Gerzo
Bret Goodfellow [BG], on Wednesday, June 22, 2005 at 15:55 (-0600)
wrote these comments:

This is what I actually did to resolve my issue:
@words = split(/ * /, $line)
Print the third word is: $words[2]\n;

this is not good, you don't know about regexpes much, eh?
first argument in split is //, where inside of those braces is regexp.
What you have will work, but it is possible, you have input
delimited with tabulators, and your example will not work. This is
better:
@words = split(/\s+/, $line);

this say, $line will split into @words, where delimiter is one or more
white characters (including tabs ofcoz)

-- 

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

[An android chaperone? * K'Ehleyr]



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




Re: cant locate SF:Logger.pm in @INC: how to add additional paths in @INCHi,

2005-06-23 Thread Xavier Noria
Did you actually put only one colon as in the subject SF:Logger  
instead of two?


-- fxn

PS: Please respond in the body.

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




Re: RegEx Multi-Line Matching

2005-06-23 Thread John W. Krahn

Jeff Westman wrote:


On 6/20/05, John W. Krahn [EMAIL PROTECTED] wrote:


It looks like you don't really need to use paragraph mode, this should do what
you want:

#!/usr/bin/perl
#
# tnsnames.pl -- reads tnsnames.ora, sorts by host name
use warnings;
use strict;

my $tnsFile = 'tnsnames.ora';
open F, '', $tnsFile or die Could not open file $tnsFile: $!\n;

my ( $host, $name, %tns ) = ( '', '' );
while ( F ) {
   $host = $1 if /\(HOST\s*=\s*(\w+)\)/;
   $name = $1 if /\(SERVICE_NAME\s*=\s*(\w+)\)/;
   if ( length $host and length $name ) {
   print *** RESULT : host= $host, service= $name\n;
   $tns{ $host } = $name;
   ( $host, $name ) = ( '', '' );
   }
   }
close F;

for ( sort keys %tns ) {
   printf %-8s = %s\n, $_, $tns{ $_ };
   }

__END__


Thank you for your post.  I know I could have just done some
top-down scanning for pairs (I like your style, BTW), but it seemed
safer to do multi-line matching, so I am still a bit bothered why I
couldn't get the match to work in all cases (ie, a blank line was
mandatory).

I also had a basic question on the code you sent.  You have:

 $host = $1 if /\(HOST\s*=\s*(\w+)\)/;
 $name = $1 if /\(SERVICE_NAME\s*=\s*(\w+)\)/;

This works and makes sense.  But what if the line is commented?! 
That is, when I modified this and made this:


 $host = $1 if /[^#].*\(HOST\s*=\s*(\w+)\)/;
 $name = $1 if /[^#].*\(SERVICE_NAME\s*=\s*(\w+)\)/;

it SHOULD have worked (I think!).  It still matched a line that should
have been ignored.  What am I doing wrong?!


The problem is that [^#] can match anywhere so in the string
ab#cd(HOST = xyz) it can match at 'a' or 'b' or 'c' or 'd'.

This should work better:

my $para = '';

while ( F ) {

$para  .= $_;

next if $para =~ tr/(// != $para =~ tr/)//;

$para =~ s/#.*//g;  # remove comment lines

if ( $para =~ /\(HOST\s*=\s*(\w+)\).*?\(SERVICE_NAME\s*=\s*(\w+)\)/s ) {

print *** RESULT : host= $1, service= $2\n;

$tns{ $1 } = $2;
}

$para = '';
}


for ( sort keys %tns ) {
   printf %-8s = %s\n, $_, $tns{ $_ };
   }



John
--
use Perl;
program
fulfillment

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




Re: cgi link

2005-06-23 Thread Brent Clark

Graeme St.Clair wrote:

Try something like:-

$html .= start_html( -title  = Rhubarb,
-style  = { 'src' = '../rhubarb.css' },
-script = [ { 'src' = '../rhubarb.js' },
   $jscript ]
  );

HTH, GStC.



ahh worked like a charm

thanks

Brent

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




XML

2005-06-23 Thread Brent Clark

Hi list

I have my code as so:

use XML::Simple;
my $xml = new XML::Simple (NoAttr=1,  RootName = 'data');

	my $data = 
$xml-XMLin(http://testbox/cgi-bin/ecco/scripts/common/bookinngsXmlDisplay.pl?lts;);


use Data::Dumper;
print Dumper(\$data)

I have a perl script export an XML schema etc.

I now need to get the xml schema back.

with the code about I get this message:

Could not find 
http://localhost/cgi-bin/ecco/scripts/common/bookinngsXmlDisplay.pl?lts 
in  at C:/Program Files/Apache 
Group/Apache2/cgi-bin/ecco/scripts/common/getXmlAgents.pl line 104


So obviously it looking for the file and not making a http connection.

If anyone has any tips or advice, it would be great fully be appreciated

Kind Regards
Brent Clark

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




XML:Twig print and delete

2005-06-23 Thread Nan Jiang

Hi all,

How to use XML:Twig print to print to a file and how to use delete to delete 
an element?


For print to a file: I tired what FAQ says but it doesn't work, the file 
size is always 0. Belows are my codes:


#!/usr/bin/perl
use warnings;
use strict;
use XML::Twig;

my $twig= XML::Twig-new( twig_roots = {Topic = 1},
twig_handlers = { 'RDF/Topic' = \topic }
   );
$twig-parsefile( './content.example.txt');

{
open(FH, diet.xml) or die cannot open diet.xml: $!;
my $count = 0;

 sub topic {

   my ($twig, $topic) = @_;

   if ($topic-children('link') or $topic-children('link1')){ #this if 
subroutine is used for output Topic/ with link(1)/ elements only

  $twig-print(\*FH);
}
$twig-purge;
 }
 close FH;
}


Many many thanks,

Nan



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




Re: XML

2005-06-23 Thread Randal L. Schwartz
 Brent == Brent Clark [EMAIL PROTECTED] writes:

Brent  my $data =
Brent 
$xml-XMLin(http://testbox/cgi-bin/ecco/scripts/common/bookinngsXmlDisplay.pl?lts;);

Do you have a file with that name?

Why would you think that would work?  The docs don't say that it
understands URLs.

Brent So obviously it looking for the file and not making a http connection.

Yes, obviously.

Brent If anyone has any tips or advice, it would be great fully be appreciated

Well, if XML::Simple doesn't grok a URL, perhaps you should give it a
file instead?

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
merlyn@stonehenge.com URL:http://www.stonehenge.com/merlyn/
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

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




date range....

2005-06-23 Thread DBSMITH
People of the Perl,

I have a need to develop some logic to automatically pick up a publc key
for my gpg keyring.  I will use cURL ( client for URL lookups ) language
for the actual download , but the catch is the expiration time of our key
which is 2005-11-16.  So I want to say if calc data =~ current date then
call cURL.
I tried an ascii increment but this only incremented from 2005-06-23 to
2006.  Maybe I am going about this all wrong???
My like operator really needs to say + - 7 days from 2005-11-16 then call
cURL and check for a new public key.

Here is my code:


require 5.8.0;
use strict;
use warnings;

# for talx expiration date of their pubkey 2005-11-16

our $time = $^T;
$ENV{PATH} =
qq(/home/gpghrp/.gnupg/scripts:/usr/local/bin:/bin:/usr/bin);


##--## Begin Routines ##--##

sub dateme
{
my ($year,$month,$day) = (localtime)[5,4,3];
sprintf (%04d-%02d-%02d\n, ($year += 1900),
$month+1,$day);
}
my $curtdate = dateme();
#print $curtdate,\n;

sub date_manip_fwd_6mths
{
use constant ONE_DAY = 86400;
use constant THIRTY_DAYS = ONE_DAY * 30;
use constant SIX_MTHS = THIRTY_DAYS * 5;
my $days = (shift);
my ($y,$m,$d) = (localtime($time + $days)) [5,4,3];
sprintf (%04d-%02d-%02d, ($y += 1900), $m+1,$d);
}

my $calcdate = date_manip_fwd_6mths(SIX_MTHS);
#print $calcdate,\n;
#my $calcdate = date_manip_fwd_6mths();


##--## Main ##--##
print $calcdate\n$curtdate;
if ( $calcdate eq $curtdate ) {
print YES\n;
print $calcdate\n$curtdate;
}

__END_CODE__

__BEGIN_DATA__

2005-11-20
2005-06-23




Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams
614-566-4145


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




Installing XML::LibXML

2005-06-23 Thread Alois Heuböck
Hello,

I'm trying to get XML::LibXML to work, but keep getting an error message: 

---
Can't locate loadable object for module XML::LibXML::Common in @INC(@INC
contains: C:/Perl/lib C:/Perl/site/lib .) at C:/Perl/lib/XML/LibXML.pm line
11
Compilation failed in require at C:/Perl/lib/XML/LibXML.pm line 11.
BEGIN failed--compilation aborted at C:/Perl/lib/XML/LibXML.pm line 11.
Compilation failed in require at MYSCRIPT.pl line 4.
BEGIN failed--compilation aborted at MYSCRIPT.pl line 4.
---

Now, I'm aware of the dependencies of LibXML -- and thought I had
(correctly) installed:

libxml2
XML::LibXML::Common
XML::SAX
XML::NamespaceSupport

Despite the various readme files, I'm still not sure what should go where,
or why what I've done is incorrect.

Could anyone help?
Thanks a lot!!

Alois

-- 
Weitersagen: GMX DSL-Flatrates mit Tempo-Garantie!
Ab 4,99 Euro/Monat: http://www.gmx.net/de/go/dsl

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




Re: date range....

2005-06-23 Thread Jay Savage
On 6/23/05, [EMAIL PROTECTED] [EMAIL PROTECTED] wrote:
 People of the Perl,
 
 I have a need to develop some logic to automatically pick up a publc key
 for my gpg keyring.  I will use cURL ( client for URL lookups ) language
 for the actual download , but the catch is the expiration time of our key
 which is 2005-11-16.  So I want to say if calc data =~ current date then
 call cURL.
 I tried an ascii increment but this only incremented from 2005-06-23 to
 2006.  Maybe I am going about this all wrong???
 My like operator really needs to say + - 7 days from 2005-11-16 then call
 cURL and check for a new public key.
 
 Here is my code:
 
 
 require 5.8.0;
 use strict;
 use warnings;
 
 # for talx expiration date of their pubkey 2005-11-16
 
 our $time = $^T;
 $ENV{PATH} =
 qq(/home/gpghrp/.gnupg/scripts:/usr/local/bin:/bin:/usr/bin);
 
 
 ##--## Begin Routines ##--##
 
 sub dateme
 {
 my ($year,$month,$day) = (localtime)[5,4,3];
 sprintf (%04d-%02d-%02d\n, ($year += 1900),
 $month+1,$day);
 }
 my $curtdate = dateme();
 #print $curtdate,\n;
 
 sub date_manip_fwd_6mths
 {
 use constant ONE_DAY = 86400;
 use constant THIRTY_DAYS = ONE_DAY * 30;
 use constant SIX_MTHS = THIRTY_DAYS * 5;
 my $days = (shift);
 my ($y,$m,$d) = (localtime($time + $days)) [5,4,3];
 sprintf (%04d-%02d-%02d, ($y += 1900), $m+1,$d);
 }
 
 my $calcdate = date_manip_fwd_6mths(SIX_MTHS);
 #print $calcdate,\n;
 #my $calcdate = date_manip_fwd_6mths();
 
 
 ##--## Main ##--##
 print $calcdate\n$curtdate;
 if ( $calcdate eq $curtdate ) {
 print YES\n;
 print $calcdate\n$curtdate;
 }
 
 __END_CODE__
 
 __BEGIN_DATA__
 
 2005-11-20
 2005-06-23

Derek,

Check out Date::Calc. I'd do somthing like this:

  #!/usr/bin/perl

  use warnings;
  use strict;

  use Date::Calc qw(Delta_Days);

  my $target = 2005-11-16;

  my ($nowyr, $nowmo, $nowday) = (localtime)[5,4,3];
  my ($taryr, $tarmo, $tarday) = split /-/, $target;
  
  my $diff = Delta_Days($nowyr + 1900, $nowmo, $nowday, $taryr,
$tarmo, $tarday);

  if ( abs($diff) = 7 ) {
system(curl, args);
# but why not use lwp?
  }


HTH,

-- jay

daggerquill [at] gmail [dot] com
http://www.tuaw.com
http://www.dpguru.com
http://www.engatiki.org

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




Perl Hash Question.

2005-06-23 Thread Anthony Roe
Hi there everybody, I have a question and I am pretty stumped for the answer.

I have a program that does the following:

A = Reads URI from URIHASH.
Visits site A.
Parses all URIS on site A and for each URI found adds the URI to the URIHASH.

A = Reads next URI from URIHASH.
Visits site A.

And so on... until the MAX URIHASH size is reached.

My question is, is there any way to iterate through a hash in this manner.

I tried foreach():

foreach $key (keys %URIHASH){}

and this does not work. What occurs is the entry that exists in the
URIHASH when the foreach loop is entered, is processed.
any additional entries that are added during the loop are not processed.

I also tried each():

while (($key, $entry) = each %URIHASH){}

When additional entries are added during the loop, this seems to
produce unexpected behaviour. In my case an infinite loop.


I should also mention that the URIHASH is tied to a file on the disk.

Any help at all would be appreciated.

Thank you very much.

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