RE: Query string to URL?

2005-03-08 Thread Jan Eden
Chris Devers wrote on 07.03.2005:

On Mon, 7 Mar 2005, Jan Eden wrote:

 But I need some rule to do this:
 
 http://mysite.com/pages?id=1234 - http://mysite.com/pages/1234
 
 And since mod_rewrite does not parse the query string, I have a 
 problem here.

So use redirect instead of rewrite:

RedirectMatch /pages?id=(.*) http://mysite.com/pages/$1
 
Won't that work?

Ah, now I remember why this won't work: I use several different hostnames for 
my site, and I do not want them to have them changed when redirecting URLs.

Cheers,

Jan
-- 
Hanlon's Razor: Never attribute to malice that which can be adequately 
explained by stupidity.

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




How to remove everything after the last . dot?

2005-03-08 Thread Bastian Angerstein

I have a line:
  i.like.donuts.but.only.with.tea

now I want to remove everything that follows the last .
including the last ..

in this case .tea

I hav absulte no idea. I tried something like:

@parts = splite /\./, $line; 

$parts[-1] = undef;

foreach $parts (@parts) {
  $newline .= $parts.;
}

but then I got a dot at the end of the line.

Thanks,

Bastian

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




xml error

2005-03-08 Thread Octavian Rasnita
Hi,

I am using a simple program that downloads an XML file from a web site, then
gets the data from it using XML::Simple, but sometimes, it gives the
following error:

not well-formed (invalid token) at line 2, column 39381, byte 39420 at
D:/usr/site/lib/XML/Parser.pm line 187

I have previously saved the downloaded XML file in order to see what's wrong
with it, but the file has less than 39420  chars with 2 chars. And it seems
to be ok.

But maybe sometime the format of the generated XML file is bad... I would
like to let the program run without dying with that error.

Please help!

Thank you.

Teddy


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




Re: How to remove everything after the last . dot?

2005-03-08 Thread John Doe
Hi 

 I have a line:
   i.like.donuts.but.only.with.tea

 now I want to remove everything that follows the last .
 including the last ..

[...]

you can use a regex for that.

=== Documentation (from command line:)


perldoc perlre

=== Code:

use strict; use warnings;
my $a=i.like.donuts.but.only.with.tea;
$a=~s/\.\d+$//; #  this does the trick
print $a, \n;

# this prints: 
i.like.donuts.but.only.with.tea

=== explanation: 
see documentation ;-)


greetings joe

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




reading an file

2005-03-08 Thread E.Horn
Hello!
I want to read this file into an array.
How can i just get 4, 5, 6,7,8 into an array?
And later, how can i get the contents out of this array?
1)2)3)   4)  5)6)
7)8)   9)10)11)
ATOM   2909  CG1   VAL B 183   1.130  28.458 104.360  1.00
23.04   C
ATOM   2910  CG2   VAL B 183   0.996  29.769 102.236  1.00
24.61   C
ATOM   2911  N   THR B 184   3.313  31.739 103.453  1.00
25.98   N
ATOM   2912  CA THR B 184   3.261  33.012 104.149  1.00
29.31   C
ATOM   2913  C   THR B 184   1.911  33.642 103.859  1.00
29.26   C
ATOM   2914  O   THR B 184   1.442  33.626 102.720  1.00
28.75   O
regards


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




Re: Appending constant string to variable inside a here-document

2005-03-08 Thread David Storrs
On Sun, Mar 06, 2005 at 11:21:23PM -0600, Charles K. Clarkson wrote:
 Harold Castro mailto:[EMAIL PROTECTED] wrote:

 : if the current content of $word is the word big, and
 : I would want to print a here document appending
 : something to big like foot:
 : 
 : print EOF;
 : 
 : $word.foot - won't work, display it as is.
 : $word.foot   - neither this one
 : $wordfoot- error. it becomes a single
 :  variable named $wordfoot
 : 
 : EOF
 
 my $word = 'big';
 
 print EOF;
 
 ${word}foot - Works Fine.
 
 EOF
 
 Charles K. Clarkson

Harold,

It looks like Charles already answered your question, but I wanted to
offer a couple of other thoughts that you might find useful.


1) A here-doc is really just a long string.  It can be either single-
   or double-quoted, but it defaults to double-quoted, like so:
  
  print 'SINGLE';  # single quoted
  print DOUBLE;  # double quoted
  print DOUBLE;# double quoted


2) Because it's a string, you can do variable interpolation in it if
   it's double-quoted, but not if it's single-quoted. For example:

  my $word = 'big';
  print EOF;  # double quotes, allows interpolation
  $word.foot   
  EOF

   is effectively the same as:

  print $word.\foot\   # big.foot

   While:
 
  my $word = 'big';
  print 'EOF';   # single quotes; no interpolation
  $word.foot   
  EOF

   is effectively the same as:

  print '$word.foot'   # $word.foot


3) Because it's a string, you cannot interpolate in a call to a
   function or operator (except see the next point).  You saw this
   when you tried to use the '.'  concatenation operator.


4) (You may want to skip this item if you aren't familiar with
   references.  Or, you can read perldoc perlref to find out about
   them.)

   If you really, really, need to interpolate something other than a
   variable into a double-quoted heredoc (or any other double-quoted
   string), you can.  It isn't pretty, but it works:

  print EOT;  # Must be double quoted (explicitly or by default)
  @{[ some_func() ]}
  EOT

   What this does is to create a reference to an anonymous array
   (that is, an array that does not have an explicit name) and then
   populate that array with the value(s) returned from
   Csome_func().  The reference to this array is then dereferenced
   into an actual array, which (just like any other array variable)
   will be interpolated into the double-quoted string that is your
   heredoc.  Whew!

   Note that you can replace Csome_func() with any arbitrary Perl
   code and it will work.  So, your C $word . foot  from above
   would have worked if you had done it this way...but the way that
   Charles suggested is /much/ better.

Hope this helps,

--Dks


  

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




Re: Changing the String of the file at one shot.

2005-03-08 Thread David Storrs
On Mon, Mar 07, 2005 at 11:00:49AM -0500, Wiggins d'Anconia wrote:
 Charles K. Clarkson wrote:
 Suneel Kumar B mailto:[EMAIL PROTECTED] wrote:
 
 : I have a situation where in, iam updating a file by replacing few
 : strings in some lines with another string. While doing this, Can i
 : have an option by which i could open a file for both read and
 : write simultaneously, so that i could search and replace the
 : string straight away..??
 
 Sounds like you need in place editing. Check out the -i switch
 in the 'perlrun' documentation for an example.
 
 Charles K. Clarkson
 
 or Tie::File,
 
 perldoc Tie::File
 
 http://danconia.org

The literal answer to your question would be this:

   open FILE, '/path/to/the/file', '+'
  or die Couldn't open: $!;

or, preferably (as it will manage some safety issues for you):

   use IO::File;
   my $file = new IO::File('/path/to/the/file', '+') 
  or die Couldn't open: $!;

This isn't a great solution for updating text files, however, since
they have variable-length records (e.g., you overwrite a 10-character
sentence with 12 characters and you have just stomped on the next 2
characters).

One of the above solutions (-i or Tie::File) will stand you in better
stead.

--Dks

-- 
[EMAIL PROTECTED]

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




Re: Changing the String of the file at one shot.

2005-03-08 Thread John Doe
Hello

see inline comment

Am Dienstag, 8. März 2005 02.04 schrieb David Storrs:
 On Mon, Mar 07, 2005 at 11:00:49AM -0500, Wiggins d'Anconia wrote:
  Charles K. Clarkson wrote:
  Suneel Kumar B mailto:[EMAIL PROTECTED] wrote:
  : I have a situation where in, iam updating a file by replacing few
  : strings in some lines with another string. While doing this, Can i
  : have an option by which i could open a file for both read and
  : write simultaneously, so that i could search and replace the
  : string straight away..??
  
  Sounds like you need in place editing. Check out the -i switch
  in the 'perlrun' documentation for an example.
  
  Charles K. Clarkson
 
  or Tie::File,
 
  perldoc Tie::File
 
  http://danconia.org

 The literal answer to your question would be this:

open FILE, '/path/to/the/file', '+'
   or die Couldn't open: $!;

open FILE, '+', '/path/to/the/file'  or die Couldn't open: $!;

(see order of arguments)

perldoc -f open

 or, preferably (as it will manage some safety issues for you):

use IO::File;
my $file = new IO::File('/path/to/the/file', '+')
   or die Couldn't open: $!;

 This isn't a great solution for updating text files, however, since
 they have variable-length records (e.g., you overwrite a 10-character
 sentence with 12 characters and you have just stomped on the next 2
 characters).

 One of the above solutions (-i or Tie::File) will stand you in better
 stead.

 --Dks

 --
 [EMAIL PROTECTED]

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




AW: How to remove everything after the last . dot?

2005-03-08 Thread Bastian Angerstein
Hmmm...

use strict; use warnings;
my $a=i.like.donuts.but.only.with.tea;
$a=~s/\.\w+$//; #  maybe w+ not d+???
print $a, \n;


Deutsche Telekom AG
T-Com, Technische Infrastruktur Niederlassung Überregional
Bastian Angerstein
Network Support Center -
Network Management Support
Maybachstr.57; D-70469 Stuttgart
+49 711 8939 1889 (Tel.)
+49 711 8939 6604 (Fax)
mailto:[EMAIL PROTECTED]
http://www.t-com.de

-Ursprüngliche Nachricht-
Von: John Doe [mailto:[EMAIL PROTECTED]
Gesendet: Dienstag, 8. März 2005 11:46
An: beginners@perl.org
Betreff: Re: How to remove everything after the last . dot?


Hi

 I have a line:
   i.like.donuts.but.only.with.tea

 now I want to remove everything that follows the last .
 including the last ..

[...]

you can use a regex for that.

=== Documentation (from command line:)


perldoc perlre

=== Code:

use strict; use warnings;
my $a=i.like.donuts.but.only.with.tea;
$a=~s/\.\d+$//; #  this does the trick
print $a, \n;

# this prints:
i.like.donuts.but.only.with.tea

=== explanation:
see documentation ;-)


greetings joe

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




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




Re: AW: How to remove everything after the last . dot?

2005-03-08 Thread Ing. Branislav Gerzo
Bastian Angerstein [BA], on Tuesday, March 8, 2005 at 12:19 (+0100)
wrote:

BA use strict; use warnings;
BA my $a=i.like.donuts.but.only.with.tea;
BA $a=~s/\.\w+$//; #  maybe w+ not d+???
BA print $a, \n;

correct code is:

use strict;
use warnings;
my $a = 'i.like.donuts.but.only.with.tea';
$a =~ s/\.[^.]+$//;
print $a, \n;

if you use this for domains don't forget about .co.uk and so on:)

-- 

 ...m8s, cu l8r, Brano.

[OS/2 means 2x as OutStanding as Windows]



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




Re: reading an file

2005-03-08 Thread Ramprasad A Padmanabhan
E.Horn wrote:
Hello!
I want to read this file into an array.
How can i just get 4, 5, 6,7,8 into an array?
Post what you have already tried.  What you want to do is not very clear.
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: AW: How to remove everything after the last . dot?

2005-03-08 Thread Ramprasad A Padmanabhan
Bastian Angerstein wrote:
Hmmm...
use strict; use warnings;
my $a=i.like.donuts.but.only.with.tea;
$a=~s/\.\w+$//; #  maybe w+ not d+???
Better still
$a =~s/\.[^.]+$//;
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: How to remove everything after the last . dot?

2005-03-08 Thread Ramprasad A Padmanabhan
Bastian Angerstein wrote:
I have a line:
  i.like.donuts.but.only.with.tea
now I want to remove everything that follows the last .
including the last ..
in this case .tea
Use Regex
To read the manual
perldoc perlre
Of course In your case you could simply do something like this
$line =~s/\.[^.]+$//;
Thanks
Ram
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: How to remove everything after the last . dot?

2005-03-08 Thread Gretar Mar Hreggvidsson
Hi!
There is actually slight error in this code.
 $a=~s/\.\d+$//; #  this does the trick
This handles only one or more digits (\d stand for digits), so unless 
the last part of the string is a number this won't work.
Should be something like

$a=~s/\.\w+$//;  # (\w stands for word charachters)
Gretar Mar
John Doe wrote:
Hi 


I have a line:
 i.like.donuts.but.only.with.tea
now I want to remove everything that follows the last .
including the last ..
[...]
you can use a regex for that.
=== Documentation (from command line:)
perldoc perlre
=== Code:
use strict; use warnings;
my $a=i.like.donuts.but.only.with.tea;
$a=~s/\.\d+$//; #  this does the trick
print $a, \n;
# this prints: 
i.like.donuts.but.only.with.tea

=== explanation: 
see documentation ;-)

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



Re: AW: How to remove everything after the last . dot?

2005-03-08 Thread John Doe
Hi Bastian

 Hmmm...

Aaaarrgghh!!

 use strict; use warnings;
 my $a=i.like.donuts.but.only.with.tea;
 $a=~s/\.\w+$//; #  maybe w+ not d+???
 print $a, \n;

Yes, of course it should be \w, not \d !

I made it wrong in the test code, then corrected, then pasted the wrong 
version...

sorry!!


To the people who suggested 

: $a =~ s/\.[^.]+$//;

My thought to use \w and not [^.] was that I assumed (wrong, since the OP did 
not say that) the string consisting of dots and words only, and then I 
considered some input sanitizing... good intent, bad result ;-)

sorry for that too.


greetings joe


 Deutsche Telekom AG
 T-Com, Technische Infrastruktur Niederlassung Überregional
 Bastian Angerstein
 Network Support Center -
 Network Management Support
 Maybachstr.57; D-70469 Stuttgart
 +49 711 8939 1889 (Tel.)
 +49 711 8939 6604 (Fax)
 mailto:[EMAIL PROTECTED]
 http://www.t-com.de

 -Ursprüngliche Nachricht-
 Von: John Doe [mailto:[EMAIL PROTECTED]
 Gesendet: Dienstag, 8. März 2005 11:46
 An: beginners@perl.org
 Betreff: Re: How to remove everything after the last . dot?


 Hi

  I have a line:
i.like.donuts.but.only.with.tea
 
  now I want to remove everything that follows the last .
  including the last ..

 [...]

 you can use a regex for that.

 === Documentation (from command line:)


 perldoc perlre

 === Code:

 use strict; use warnings;
 my $a=i.like.donuts.but.only.with.tea;
 $a=~s/\.\d+$//; #  this does the trick
 print $a, \n;

 # this prints:
 i.like.donuts.but.only.with.tea

 === explanation:
 see documentation ;-)


 greetings joe

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

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




Re: reading an file

2005-03-08 Thread Steven Schubiger
On  8 Mar, E.Horn wrote:

 Hello!
 I want to read this file into an array.
 How can i just get 4, 5, 6,7,8 into an array?
 And later, how can i get the contents out of this array?
 1)2)3)   4)  5)6)
 7)8)   9)10)11)
 ATOM   2909  CG1   VAL B 183   1.130  28.458 104.360  1.00
 23.04   C
 ATOM   2910  CG2   VAL B 183   0.996  29.769 102.236  1.00
 24.61   C
 ATOM   2911  N   THR B 184   3.313  31.739 103.453  1.00
 25.98   N
 ATOM   2912  CA THR B 184   3.261  33.012 104.149  1.00
 29.31   C
 ATOM   2913  C   THR B 184   1.911  33.642 103.859  1.00
 29.26   C
 ATOM   2914  O   THR B 184   1.442  33.626 102.720  1.00
 28.75   O
 regards

#! /usr/bin/perl

use strict;
use warnings;

# Each element in an interpolated array
# is followed by a trailing newline
$ = \n;

my $file = '/path/to/file';

open(FH, $file) or die Couldn't open $file: $!\n;
while (my $line = FH) {
# Remove all whitespaces (and trailing newline) 
# and insert remaining items in @arr
my @arr = split /\s+/, $line;
# Remove first of first three and last two elements
splice(@arr, 0, 3)  splice(@arr, -2, $#arr);
# Separate 'VAL B' into array
my @tmp = splice(@arr, 0, 2);
my $tmp;
# @tmp = qw(VAL B) becomes string 'VAL B'
$tmp .= $_  for @tmp;
# Remove trailing space and insert at front of @arr
chop($tmp)  unshift(@arr, $tmp);
# Print each element in @arr
print @arr\n\n;
}
close(FH);



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

2005-03-08 Thread Gretar M Hreggvidsson
Have you tried to open that XML page in a browser?
Do you write the XML to file before you parse it?  Then this could have 
something to do with encoding, your computer might not support the 
encoding defined in the XML header.

The XML source could also just be unreliable, lacking encoding of some 
non-valid XML charachters.  You could try to validate it using this 
online XML validator:

http://www.w3schools.com/dom/dom_validate.asp
Gretar
Octavian Rasnita wrote:
Hi,
I am using a simple program that downloads an XML file from a web site, then
gets the data from it using XML::Simple, but sometimes, it gives the
following error:
not well-formed (invalid token) at line 2, column 39381, byte 39420 at
D:/usr/site/lib/XML/Parser.pm line 187
I have previously saved the downloaded XML file in order to see what's wrong
with it, but the file has less than 39420  chars with 2 chars. And it seems
to be ok.
But maybe sometime the format of the generated XML file is bad... I would
like to let the program run without dying with that error.
Please help!
Thank you.
Teddy
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: reading an file

2005-03-08 Thread John Doe
Hello E.

 Hello!
 I want to read this file into an array.
 How can i just get 4, 5, 6,7,8 into an array?
 And later, how can i get the contents out of this array?
 1)2)3)   4)  5)6)
 7)8)   9)10)11)
 ATOM   2909  CG1   VAL B 183   1.130  28.458 104.360  1.00
 23.04   C
 ATOM   2910  CG2   VAL B 183   0.996  29.769 102.236  1.00
 24.61   C
 ATOM   2911  N   THR B 184   3.313  31.739 103.453  1.00
 25.98   N
 ATOM   2912  CA THR B 184   3.261  33.012 104.149  1.00
 29.31   C
 ATOM   2913  C   THR B 184   1.911  33.642 103.859  1.00
 29.26   C
 ATOM   2914  O   THR B 184   1.442  33.626 102.720  1.00
 28.75   O
 regards

Hmmm... your description is a bit small, as  Ramprasad A Padmanabhan already 
wrote.

I reformatted your lines and guess that you have a fixed format file with 
every value in well defined columns, and every line with the same length.

_IF_ this is the case, then you _could_  follow several strategies:

a) split every line into chars and extract the appropriate
b) use a regex extracting according to positions
c) use a regex extracting patterns

I think the best and simplest method would be strategy b):
- independent from char/alpha/digit at the positions
- goes also if no spaces between values

Since your lines are line breaked, I use a simplified example.
For reading in a file line by line into a variable, see Steven's code.

I only demonstrate the extraction of one already read line; 
and I extract the 1st and the 3rd value (you can easily adapt it to your 
actual line layout, I suppose you will have some variable descriptions with 
start- and end-positions)

# intro
#
use strict; use warnings;

# a line example
#
my $line='ATOM   2909  CG1   VAL B'; # incomplete demo line!

# direct extraction (result pieces left aligned). 
# Note the o modifier and the () around the 1st and 3rd piece
#
my @parts= $line=~/^(.{7}).{6}(.{6}).{5}/o;  

# trim right space away. I'm shure there is a shorter
# and more elegant solution
#
@parts= map { do {$_=~s/\s*$//; $_ } } @parts;

# print
#
print join , , @parts;
print \n;

# This prints:
ATOM, CG1

If you need more detailed explanation of the code, just ask - and also consult 
the documentation:

perldoc perlre
perldoc perldata
(at least)


greetings joe


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




RE: reading an file

2005-03-08 Thread Giff Hammar
One way:

open(FOO,filename) || die Couldn't open filename: !$\n;
while(FOO) {
chomp();
($t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10,$t11) = split;
$interestingdata = join(|,$t4,$t5,$t6,$t7,$t8);
$atomhash{$t2} = $interestingdata;
}

It would be more enlightening to name the variables so you
know what they are. To extract, you have to either walk through
the entire hash or selectively extract the ones you want.

Selective:

$wanttosee = $atomhash{$somenumber};

Everything:

while (($atom,$values) = each(%atomhash)) {
($t4,$t5,$t6,$t7,$t8) = split(/|\/,$values);
# do something useful here. The print is a sample
print Atom number is $atom. Data are:\n
print \t$t4\t$t5\t$t6\t$t7\t$t8\n;
}

Giff

-Original Message-
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, 08 March, 2005 05:52
To: beginners@perl.org
Subject: reading an file 

Hello!
I want to read this file into an array.
How can i just get 4, 5, 6,7,8 into an array?
And later, how can i get the contents out of this array?
1)2)3)   4)  5)6)
7)8)   9)10)11)
ATOM   2909  CG1   VAL B 183   1.130  28.458 104.360  1.00
23.04   C
ATOM   2910  CG2   VAL B 183   0.996  29.769 102.236  1.00
24.61   C
ATOM   2911  N   THR B 184   3.313  31.739 103.453  1.00
25.98   N
ATOM   2912  CA THR B 184   3.261  33.012 104.149  1.00
29.31   C
ATOM   2913  C   THR B 184   1.911  33.642 103.859  1.00
29.26   C
ATOM   2914  O   THR B 184   1.442  33.626 102.720  1.00
28.75   O
regards


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


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




Re: reading an file

2005-03-08 Thread Steven Schubiger

 # trim right space away. I'm shure there is a shorter
 # and more elegant solution
 #
 @parts= map { do {$_=~s/\s*$//; $_ } } @parts;

Regular expressions have a tendency to be slower, than functions
that achieve aquivalent results; but, chop() cannot be considered being
used in above statement, since chops returns the trimmed character.

s/// operates by default on $_, as many other built-in functions do,
thus:

@parts = map { do { s/\s*$//; $_ } @parts;

Also, consider using the tr operator instead of s/// for speed-up 
purposes.




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




Re: reading an file

2005-03-08 Thread John Doe
Hello Steven

Am Dienstag, 8. März 2005 15.19 schrieb Steven Schubiger:
  # trim right space away. I'm shure there is a shorter
  # and more elegant solution
  #
  @parts= map { do {$_=~s/\s*$//; $_ } } @parts;

 Regular expressions have a tendency to be slower, than functions
 that achieve aquivalent results; but, chop() cannot be considered being
 used in above statement, since chops returns the trimmed character.

Must chop be used in the above statement? @parts contains no line end - I 
think - after something like

 my @parts= $line=~/^(.{7}).{6}(.{6}).{5}/o;  

?

 s/// operates by default on $_, as many other built-in functions do,
 thus:

 @parts = map { do { s/\s*$//; $_ } @parts;

Thanks :-) 
[just a very little typo note: one right '}' is missing]

What do you think if one would also put an o modifier here?

 @parts = map { do { s/\s*$//o; $_ } } @parts;

Would this still be (much) slower than the tr/// version?
[hmm... ok... I could test it myself]

 Also, consider using the tr operator instead of s/// for speed-up
 purposes.

Oups - I missed this possibility... which would be (just to be complete :-)

 @parts = map { do { tr/ //d; $_ }} @parts; # d modifier required
 
 
Thanks again :-)

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




Regex Multi line match

2005-03-08 Thread William Melanson

Greetings,

This is the multi line pattern in which I wish to match:

tr
tdb String 1.2.3.4.5.6 /b/td
tdimg src=pics/green.gif alt=OK/td
tr

This is what I have:

==
#!/usr/bin/perl -w

my $file='./index.html';

open INFILE, $file or die Can't open $file: $!;
while (INFILE)
{
if (/^tr\n
 ^tdb String 1\.2\.3\.4\.5\.6 /b/td\n
 ^tdimg src\=\pics/green\.gif\ alt\=\OK\/td\n
 ^tr\n/smx) {

 print($_);
}
}
close INFILE;

==

What have I been overlooking?

Thanks much


-- 


Regards,

Bill

==
William Melanson: WebUnited Systems Administration
Phone: 954-418-8884 Ext: 287
==



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




Re: reading an file

2005-03-08 Thread John Doe
Hello again Steve

Am Dienstag, 8. März 2005 15.46 schrieb John Doe:
 Hello Steven
[...]
  s/// operates by default on $_, as many other built-in functions do,
  thus:
 
  @parts = map { do { s/\s*$//; $_ } @parts;

 Thanks :-)
 [just a very little typo note: one right '}' is missing]

 What do you think if one would also put an o modifier here?

  @parts = map { do { s/\s*$//o; $_ } } @parts;

 Would this still be (much) slower than the tr/// version?
 [hmm... ok... I could test it myself]

  Also, consider using the tr operator instead of s/// for speed-up
  purposes.

 Oups - I missed this possibility... which would be (just to be complete :-)

  @parts = map { do { tr/ //d; $_ }} @parts; # d modifier required
[...]

I just realized that the tr is not applicable in the case of the present data 
because column 4 which contains spaces _within_ the value
(e.g. VAL B).


Then I ran the following test with (for me) not very expected results - maybe 
the test is bad designed?

# I ran 3 times:

use strict; 
use warnings;
use Benchmark 'cmpthese';

my $line='ATOM   2909  CG1   VAL B'; # incomplete demo line!

my @parts= $line=~/^(.{7}).{6}(.{6}).{5}/o;  

cmpthese( -1, { 
 common = 'my @[EMAIL PROTECTED];', 
 s  = 'my @[EMAIL PROTECTED]; @p=map {do{s/\s*$//; $_}} @p;', 
 so = 'my @[EMAIL PROTECTED]; @p=map {do{s/\s*$//o; $_}} @p;', 
 tr  = 'my @[EMAIL PROTECTED]; @p=map {do{tr/ //d;  $_}} @p;' 
} ) ;

# With the results:

Rate tr  s so common
tr  607350/s ---1%-2%   -47%
s   613304/s 1% ---1%   -46%
so  619376/s 2% 1% --   -46%
common 1137401/s87%85%84% --

Rate  s tr so common
s   607350/s ---0%-1%   -45%
tr  607350/s 0% ---1%   -45%
so  613304/s 1% 1% --   -45%
common 1113476/s83%83%82% --


Rate tr so  s common
tr  595781/s ---4%-5%   -44%
so  619376/s 4% ---1%   -42%
s   626447/s 5% 1% --   -42%
common 1071850/s80%73%71% --

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

2005-03-08 Thread John Doe
Am Dienstag, 8. März 2005 17.20 schrieb William Melanson:
 Greetings,

Greetings too :-)

 This is the multi line pattern in which I wish to match:

 tr
 tdb String 1.2.3.4.5.6 /b/td
 tdimg src=pics/green.gif alt=OK/td
 tr

 This is what I have:

 ==
 #!/usr/bin/perl -w

 my $file='./index.html';

 open INFILE, $file or die Can't open $file: $!;
 while (INFILE)
 {
 if (/^tr\n
  ^tdb String 1\.2\.3\.4\.5\.6 /b/td\n
  ^tdimg src\=\pics/green\.gif\ alt\=\OK\/td\n
  ^tr\n/smx) {

  print($_);
 }
 }
 close INFILE;

 ==

 What have I been overlooking?

that 

 while (INFILE)

reads just _one_ line at the time :-)


[...]

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




thanks

2005-03-08 Thread eva . horn
Thanks everybody...
The support was great!!!
Regards

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




output from system call

2005-03-08 Thread geraldine_1
Hi,
Is there a way to store the output of a system call on unix?

eg. system(date);

I like to store the date output to a variable.  The only way I know of is to 
open and write the output to a file and then read in to a variable. Is there a 
simpler way?

Thanks in advance.

Geraldine

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




Re: output from system call

2005-03-08 Thread Ankur Gupta
[EMAIL PROTECTED] wrote:
Hi,
Is there a way to store the output of a system call on unix?
eg. system(date);
use backticks...
$date = `date`;
Don't forget to chomp the $date variable as I guess you just want the date, not 
the newline character with it...
chomp($date);

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



Re: output from system call

2005-03-08 Thread mgoland


- Original Message -
From: [EMAIL PROTECTED]
Date: Tuesday, March 8, 2005 11:29 am
Subject: output from system call

 Hi,
Hello,
 Is there a way to store the output of a system call on unix?
 
sure
 eg. system(date);

my $Date = system(date);

 
 I like to store the date output to a variable.  The only way I 
 know of is to open and write the output to a file and then read in 
 to a variable. Is there a simpler way?
 
 Thanks in advance.
 
 Geraldine
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 
 


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




RE: output from system call

2005-03-08 Thread Manav Mathur

chomp($date=`date`) ; ##exploiting what Perl offers but C doesnt


-Original Message-
From: Ankur Gupta [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 08, 2005 10:03 PM
To: [EMAIL PROTECTED]
Cc: beginners@perl.org
Subject: Re: output from system call


[EMAIL PROTECTED] wrote:

Hi,
Is there a way to store the output of a system call on unix?

eg. system(date);

use backticks...

$date = `date`;

Don't forget to chomp the $date variable as I guess you just want the date,
not the newline character with it...

chomp($date);




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



*
Disclaimer:

The contents of this E-mail (including the contents of the enclosure(s) or 
attachment(s) if any) are privileged and confidential material of MBT and 
should not be disclosed to, used by or copied in any manner by anyone other 
than the intended addressee(s).   In case you are not the desired addressee, 
you should delete this message and/or re-direct it to the sender.  The views 
expressed in this E-mail message (including the enclosure(s) or attachment(s) 
if any) are those of the individual sender, except where the sender expressly, 
and with authority, states them to be the views of MBT.

This e-mail message including attachment/(s), if any, is believed to be free of 
any virus.  However, it is the responsibility of the recipient to ensure that 
it is virus free and MBT is not responsible for any loss or damage arising in 
any way from its use

*

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




tricky hash

2005-03-08 Thread Ing. Branislav Gerzo
Hello beginners@perl.org,

anyone could me help with:

use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw-{cnt}++; 
$kw-{cat${kw-{cnt}}} = $cat }


I get: Can't use bareword (kw) as a HASH ref while strict refs in
use..
The goal is to get something like:
$kw-{cat1} = 'something',
$kw-{cat2} = 'other',
$kw-{cat3} = 'foo',
$kw-{cat4} = 'bar'

anyone?

--

 --. ,--  ,- ICQ: 7552083  \|||/`//EB: www.2ge.us
,--' |  - |--IRC: [2ge](. .),\\SN: 2ge!2ge_us
`+==+=+===~  ~=-o00-(_)-00o-~
When hell freezes over?  I just sold Satan a fur coat the other day...
 




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




Re: output from system call

2005-03-08 Thread Wiggins d'Anconia
[EMAIL PROTECTED] wrote:
Hi,
Is there a way to store the output of a system call on unix?
eg. system(date);
I like to store the date output to a variable.  The only way I know of is to 
open and write the output to a file and then read in to a variable. Is there a 
simpler way?
Thanks in advance.
Geraldine
As the others have mentioned you can use the backticks to store the 
output. But please only use this method when it is absolutely necessary. 
Perhaps you just gave an example, but in case not, you can get the 
current date from Perl itself much easier and much more safely.

Shelling out to a command using system or backticks is a *last resort*. 
If there is something you don't know how to do in Perl or if it can be 
done in Perl ask first, use 'system' et al second.

You need to check the return value of system, and whether the program 
executed at all, you should consider full paths, make sure you have 
taint checks on, and be sure to read the documentation for the program 
you are calling thoroughly to understand its interface. In general 
shelling out is slower, more error prone, less secure, and when done 
right takes longer to code.

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



RE: tricky hash

2005-03-08 Thread Manav Mathur

use strict;
use warnings;
use Data::Dumper ;
my %kw = ();
my $kw = \%kw;
my $i = 1;
for my $cat (split(/\//, 'something/other/foo/bar'))
{
$kw-{cat.eval{$i++}} = $cat
}
print Dumper \%kw ;

-Original Message-
From: Ing. Branislav Gerzo [mailto:[EMAIL PROTECTED]
Sent: Tuesday, March 08, 2005 10:14 PM
To: beginners@perl.org
Subject: tricky hash


Hello beginners@perl.org,

anyone could me help with:

use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw-{cnt}++;
$kw-{cat${kw-{cnt}}} = $cat }


I get: Can't use bareword (kw) as a HASH ref while strict refs in
use..
The goal is to get something like:
$kw-{cat1} = 'something',
$kw-{cat2} = 'other',
$kw-{cat3} = 'foo',
$kw-{cat4} = 'bar'

anyone?

--

 --. ,--  ,- ICQ: 7552083  \|||/`//EB: www.2ge.us
,--' |  - |--IRC: [2ge](. .),\\SN: 2ge!2ge_us
`+==+=+===~  ~=-o00-(_)-00o-~
When hell freezes over?  I just sold Satan a fur coat the other day...





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



*
Disclaimer:

The contents of this E-mail (including the contents of the enclosure(s) or 
attachment(s) if any) are privileged and confidential material of MBT and 
should not be disclosed to, used by or copied in any manner by anyone other 
than the intended addressee(s).   In case you are not the desired addressee, 
you should delete this message and/or re-direct it to the sender.  The views 
expressed in this E-mail message (including the enclosure(s) or attachment(s) 
if any) are those of the individual sender, except where the sender expressly, 
and with authority, states them to be the views of MBT.

This e-mail message including attachment/(s), if any, is believed to be free of 
any virus.  However, it is the responsibility of the recipient to ensure that 
it is virus free and MBT is not responsible for any loss or damage arising in 
any way from its use

*

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




Re: tricky hash

2005-03-08 Thread Wiggins d'Anconia
Ing. Branislav Gerzo wrote:
Hello beginners@perl.org,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw-{cnt}++; 
$kw-{cat${kw-{cnt}}} = $cat }
You don't have to accept the rope Perl will give you to hang yourself,
$kw-{'cat'.$kw-{'cnt'}} = $cat;
The special quoting Perl does on hash keys is really only useful for 
simple strings.

Perl also ignores whitespace for a reason, consider not writing whole 
programs on one line, it will help you with debugging.


I get: Can't use bareword (kw) as a HASH ref while strict refs in
use..
The goal is to get something like:
$kw-{cat1} = 'something',
$kw-{cat2} = 'other',
$kw-{cat3} = 'foo',
$kw-{cat4} = 'bar'
anyone?
http://danconia.org
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/ http://learn.perl.org/first-response



Re: output from system call

2005-03-08 Thread Chris Devers
On Tue, 8 Mar 2005, Ankur Gupta wrote:

 [EMAIL PROTECTED] wrote:
 
  Hi,
  Is there a way to store the output of a system call on unix?
  
  eg. system(date);
  
 use backticks...
 
 $date = `date`;

This is, of course, exactly the wrong way to solve this problem.

Perl has date facilities built in -- so *use them*! :-)

$ perl -le '$now = scalar localtime time ; print $now'
Tue Mar  8 11:50:47 2005
$ date
Tue Mar  8 11:50:48 EST 2005
$

So, by default, you don't get the time zone the way the `date` command 
does, but if you need that, it's not hard to extract. 

See --

perldoc -f time
perldoc -f localtime

-- for details on the built in time handling functions.

If you want to get fancier, CPAN modules like Time::Local, Date::Calc, 
etc.

http://search.cpan.org/~jhi/perl-5.8.0/lib/Time/Local.pm
http://search.cpan.org/~stbey/Date-Calc-5.4/Calc.pod

And so on.

There's a lot of thing that can be legitimately done by calling out to a 
system command, but getting the date isn't really one of them :-)

 

-- 
Chris Devers

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




Re: tricky hash

2005-03-08 Thread Ankur Gupta
Ing. Branislav Gerzo wrote:
Hello beginners@perl.org,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw-{cnt}++; 
$kw-{cat${kw-{cnt}}} = $cat }
Change this line to 

 for my $cat (split(/\//, 'something/other/foo/bar')) { $kw-{cnt}++; $kw-{cat 
. $kw-{cnt}} = $cat }
This should work.

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



Re: output from system call

2005-03-08 Thread geraldine_1
Thanks everyone for the input. 

Getting the date output is much easier in perl than I originally thought. 

thanks!

Geraldine


 On Tue, 8 Mar 2005, Ankur Gupta wrote:
 
  [EMAIL PROTECTED] wrote:
  
   Hi,
   Is there a way to store the output of a system call on unix?
   
   eg. system(date);
   
  use backticks...
  
  $date = `date`;
 
 This is, of course, exactly the wrong way to solve this problem.
 
 Perl has date facilities built in -- so *use them*! :-)
 
 $ perl -le '$now = scalar localtime time ; print $now'
 Tue Mar  8 11:50:47 2005
 $ date
 Tue Mar  8 11:50:48 EST 2005
 $
 
 So, by default, you don't get the time zone the way the `date` command 
 does, but if you need that, it's not hard to extract. 
 
 See --
 
 perldoc -f time
 perldoc -f localtime
 
 -- for details on the built in time handling functions.
 
 If you want to get fancier, CPAN modules like Time::Local, Date::Calc, 
 etc.
 
 http://search.cpan.org/~jhi/perl-5.8.0/lib/Time/Local.pm
 http://search.cpan.org/~stbey/Date-Calc-5.4/Calc.pod
 
 And so on.
 
 There's a lot of thing that can be legitimately done by calling out to a 
 system command, but getting the date isn't really one of them :-)
 
  
 
 -- 
 Chris Devers

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




Re: tricky hash

2005-03-08 Thread Lawrence Statton
 Hello beginners@perl.org,
 
 
 I get: Can't use bareword (kw) as a HASH ref while strict refs in
 use..
 The goal is to get something like:
 $kw-{cat1} = 'something',
 $kw-{cat2} = 'other',
 $kw-{cat3} = 'foo',
 $kw-{cat4} = 'bar'
 

Well, fixing the typo where you build the key for the last assignment
would help with your immediate problem.  *HOWEVER*  You're still
solving the problem in a wrong-way.

*EVERY TIME* you see a list of variable names (or hash keys) of the
form foo1 foo2 foo3 foo4 that should be a GIANT WAVING RED FLAG that
your data model is lacking.

Lacking is not strong enough a word.

How about is pessimally awful.

...deserves never to see the light of day.

Perl has a built in data type highly suited for a series of data
indexed by a monotonically increasing integer.  The List.

my @keyword = split ( /\//, 'something/wicked/this/way/comes' ) ;

If you like the refence version of it

my $keywords = [ split (/\//, 'something/wicked/this/way/comes') ] ;

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
Lawrence Statton - [EMAIL PROTECTED] s/aba/c/g
Computer  software  consists of  only  two  components: ones  and
zeros, in roughly equal proportions.   All that is required is to
sort them into the correct order.








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




Re: Changing the String of the file at one shot.

2005-03-08 Thread David Storrs
On Tue, Mar 08, 2005 at 12:02:09PM +0100, John Doe wrote:
 Am Dienstag, 8. März 2005 02.04 schrieb David Storrs:
   Suneel Kumar B mailto:[EMAIL PROTECTED] wrote:
   : Can i
   : have an option by which i could open a file for both read and
   : write simultaneously

  The literal answer to your question would be this:
 
 open FILE, '/path/to/the/file', '+'
or die Couldn't open: $!;
 
 open FILE, '+', '/path/to/the/file'  or die Couldn't open: $!;
 
 (see order of arguments)
 
 perldoc -f open

Sorry, yes.  I had originally used the 'IO::File' version there, for
which that is the correct order.  When I changed it to the bare open
call, I forgot to swap them.  This difference in the order is
something that has tripped me a lot.

  or, preferably (as it will manage some safety issues for you):
 
 use IO::File;
 my $file = new IO::File('/path/to/the/file', '+')
or die Couldn't open: $!;


--Dks

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




Re: reading an file

2005-03-08 Thread Shiping Wang
Hi,
At 11:51 AM 3/8/2005 +0100, E.Horn wrote:
Hello!
I want to read this file into an array.
How can i just get 4, 5, 6,7,8 into an array?
And later, how can i get the contents out of this array?
1)2)3)   4)  5)6)
7)8)   9)10)11)
ATOM   2909  CG1   VAL B 183   1.130  28.458 104.360  1.00
23.04   C
ATOM   2910  CG2   VAL B 183   0.996  29.769 102.236  1.00
24.61   C
ATOM   2911  N   THR B 184   3.313  31.739 103.453  1.00
25.98   N
ATOM   2912  CA THR B 184   3.261  33.012 104.149  1.00
29.31   C
ATOM   2913  C   THR B 184   1.911  33.642 103.859  1.00
29.26   C
ATOM   2914  O   THR B 184   1.442  33.626 102.720  1.00
28.75   O
regards
How about this if 'VAL B' is single value and one space in between:
#! /usr/bin/perl
use strict;
use warnings;
while (DATA) {
my @array = ((split/\s+/)[3].' '.(split/\s+/)[4], (split/\s+/)[5..8]);
   print join (\t, @array, \n);
}
__DATA__
ATOM   2909  CG1   VAL B 183   1.130  28.458 
104.360  1.0023.04   C
ATOM   2910  CG2   VAL B 183   0.996  29.769 
102.236  1.0024.61   C
ATOM   2911  N   THR B 184   3.313  31.739 
103.453  1.0025.98   N
ATOM   2912  CA THR B 184   3.261  33.012 
104.149  1.0029.31   C
ATOM   2913  C   THR B 184   1.911  33.642 
103.859  1.0029.26   C
ATOM   2914  O   THR B 184   1.442  33.626 
102.720  1.0028.75   O

Shiping

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

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



Re: Regex Multi line match

2005-03-08 Thread Dave Gray
 This is the multi line pattern in which I wish to match:
 
 tr
 tdb String 1.2.3.4.5.6 /b/td
 tdimg src=pics/green.gif alt=OK/td
 tr

One way to solve this would be to read lines from the file and save
chunks of N lines (4 in this case) in a temp variable. Then your regex
would operate on enough of the file to have a chance of working.
Something like (untested):

my (@lines, $num) = ((), 4);
while (INPUT) {
  push @lines, $_;
  shift @lines if @lines == $num+1;
  print 'lines '.($.-$num+1).' to '.($.). match\n
if join('',@lines) =~ /regex goes here/;
}

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




Interpolation Problem with Matching

2005-03-08 Thread RICHARDS, JIM
I am trying to compare files names listed in a file to the actual files
in a directory.  My code is as follows:

 

Opendir(DIR,name);

@files=readdir(DIR);

 

 Open(IN,fileList);

 

While(IN) {

If(/^pattern/) {

moveFile($_);

}

}

 

Close(IN);

 

Sub moveFile() {

My [EMAIL PROTECTED];

Foreach(@files) {

If(/$src/) {

Print $_\n;

}

}

}

 

 

I know this is not the most efficient, but I do not understand why the
statement if(/$src/) is never true?  Does not seem the $src is
interpolated correctly for the match.

Why is this happening?  How can it be fixed?

 

Thanks in advance!!!

 

Jim



Re: How to remove everything after the last . dot?

2005-03-08 Thread John W. Krahn
Bastian Angerstein wrote:
I have a line:
  i.like.donuts.but.only.with.tea
now I want to remove everything that follows the last .
including the last ..
in this case .tea
substr( $line, rindex( $line, '.' ) ) = '' if $line =~ tr/.//;
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: Regex Multi line match

2005-03-08 Thread Jay Savage
On Tue, 8 Mar 2005 13:42:44 -0500, Dave Gray [EMAIL PROTECTED] wrote:
  This is the multi line pattern in which I wish to match:
 
  tr
  tdb String 1.2.3.4.5.6 /b/td
  tdimg src=pics/green.gif alt=OK/td
  tr
 
 One way to solve this would be to read lines from the file and save
 chunks of N lines (4 in this case) in a temp variable. Then your regex
 would operate on enough of the file to have a chance of working.
 Something like (untested):
 
 my (@lines, $num) = ((), 4);
 while (INPUT) {
   push @lines, $_;
   shift @lines if @lines == $num+1;
   print 'lines '.($.-$num+1).' to '.($.). match\n
 if join('',@lines) =~ /regex goes here/;
 }
 

That assumes that the pattern being searched for will begin 4n lines
from the beginning of the file, but just because we're looking for
four lines doesn't mean the file is written in four line chunks.  In
fact, it probably isn't.

Why don't you tell us what you're actually trying to do here; I'm
guessing the goal isn't to search through a file for a literal string
and then print it.  If you knew what you were looking for, you
wouldn't need to seach the file; you could just print it.  So is the
ultimate goal to perform a substitution? Count the number of
occurrances?  What?

If it's a single, reasonably sized file, try something like:

my @lines = ();
my $text = join '', @lines;
$text =~ /regex/ ;


If it's too big to hold in memory, things get a little more interesting.

HTH,

--jay

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

2005-03-08 Thread Dave Gray
  Something like (untested):
 
  my (@lines, $num) = ((), 4);
  while (INPUT) {
push @lines, $_;
shift @lines if @lines == $num+1;
print 'lines '.($.-$num+1).' to '.($.). match\n
  if join('',@lines) =~ /regex goes here/;
  }
 
 
 That assumes that the pattern being searched for will begin 4n lines
 from the beginning of the file, but just because we're looking for
 four lines doesn't mean the file is written in four line chunks.  In
 fact, it probably isn't.

Er, no it doesn't. Read it again. It's a rolling n-line chunk of the file.

 Why don't you tell us what you're actually trying to do here; I'm
 guessing the goal isn't to search through a file for a literal string
 and then print it.  If you knew what you were looking for, you
 wouldn't need to seach the file; you could just print it.  So is the
 ultimate goal to perform a substitution? Count the number of
 occurrances?  What?

Now this I agree with.

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

2005-03-08 Thread John W. Krahn
Dave Gray wrote:
This is the multi line pattern in which I wish to match:
tr
tdb String 1.2.3.4.5.6 /b/td
tdimg src=pics/green.gif alt=OK/td
tr
One way to solve this would be to read lines from the file and save
chunks of N lines (4 in this case) in a temp variable. Then your regex
would operate on enough of the file to have a chance of working.
Something like (untested):
my (@lines, $num) = ((), 4);
You are assigning the list ((), 4) to @lines and nothing to $num.  Perhaps 
you
meant:
my ( $num, @lines ) = ( 4, () );
Or simply:
my ( $num, @lines ) = 4;
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: Interpolation Problem with Matching

2005-03-08 Thread Wagner, David --- Senior Programmer Analyst --- WGO
RICHARDS, JIM wrote:
 I am trying to compare files names listed in a file to the actual
 files in a directory.  My code is as follows:
 
 
 
 Opendir(DIR,name);
 
 @files=readdir(DIR);
 
 
 
  Open(IN,fileList);
 
 
 
 While(IN) {
 
 If(/^pattern/) {
 
 moveFile($_);
 
 }
 
 }
 
 
 
 Close(IN);
 
 
 
 Sub moveFile() {
 
 My [EMAIL PROTECTED];
 
 Foreach(@files) {
 
 If(/$src/) {
Since you are using $src as the pattern, it will take any slashes it 
finds and take something like abc\g and look for abcg since a \ in pattern 
takes whatever the next character is.  So even thouhg you see abc\g, the 
pattern is looking for abcg.  Wrap the pattern in \Q$src\E which turns off any 
of the special characters.

Wags ;)

 
 Print $_\n;
 
 }
 
 }
 
 }
 
 
 
 
 
 I know this is not the most efficient, but I do not understand why the
 statement if(/$src/) is never true?  Does not seem the $src is
 interpolated correctly for the match.
 
 Why is this happening?  How can it be fixed?
 
 
 
 Thanks in advance!!!
 
 
 
 Jim



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




Re: Regex Multi line match

2005-03-08 Thread Jay Savage
On Tue, 8 Mar 2005 15:26:28 -0500, Dave Gray [EMAIL PROTECTED] wrote:
   Something like (untested):
  
   my (@lines, $num) = ((), 4);
   while (INPUT) {
 push @lines, $_;
 shift @lines if @lines == $num+1;
 print 'lines '.($.-$num+1).' to '.($.). match\n
   if join('',@lines) =~ /regex goes here/;
   }
  
 
  That assumes that the pattern being searched for will begin 4n lines
  from the beginning of the file, but just because we're looking for
  four lines doesn't mean the file is written in four line chunks.  In
  fact, it probably isn't.
 
 Er, no it doesn't. Read it again. It's a rolling n-line chunk of the file.
 

You are correct, I misread.

--j

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




Pattern matching to identify comma separated text

2005-03-08 Thread Chris Schults
I'm sending this on behalf of our intern Elmer. Thanks in advance for any
assistance. Chris

Hi there!

If anyone out there is good with Perl's pattern matching, maybe you can help
me out.  I am trying to take a string and derive information from it that is
separated by commas so I can then analyze the individual values.

So if I have a string like: 'Associated Press, John. D. Reporter, 01 Apr
2005'

I want to be able to scan it, and extract 'Associated Press' 'John. D.
Reporter' and '01 Apr 2005' as distinct values--maybe store them as
variables so I can manipulate them.

It should also be that the number of data items not be relevant.  In case
the string is like 'Joe Freelancer, 01 May 2005'  or 'Reuters, 01 Jun 2005'.
Or if it has no commas and is just '01 Jul 2005'.

Kind regards,

Elmer Zahraie



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




Re: Pattern matching to identify comma separated text

2005-03-08 Thread Wiggins d'Anconia
Chris Schults wrote:
I'm sending this on behalf of our intern Elmer. Thanks in advance for any
assistance. Chris
Hi there!
If anyone out there is good with Perl's pattern matching, maybe you can help
me out.  I am trying to take a string and derive information from it that is
separated by commas so I can then analyze the individual values.
So if I have a string like: 'Associated Press, John. D. Reporter, 01 Apr
2005'
I want to be able to scan it, and extract 'Associated Press' 'John. D.
Reporter' and '01 Apr 2005' as distinct values--maybe store them as
variables so I can manipulate them.
It should also be that the number of data items not be relevant.  In case
the string is like 'Joe Freelancer, 01 May 2005'  or 'Reuters, 01 Jun 2005'.
Or if it has no commas and is just '01 Jul 2005'.
Kind regards,
Elmer Zahraie

Check out the 'split' function.
perldoc -f split
my @items = split /,/, $string;
Is the simplest, but you may need to take into account whitespace, etc. 
 Also note that if you are parsing data that is coming in a true CSV 
format, aka with quoted values that might contain commas, etc. then you 
should consider using a module designed for this purpose, such as 
something in the Text::CSV range.

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



Re: Regex Multi line match

2005-03-08 Thread Dave Gray
  my (@lines, $num) = ((), 4);
 
 You are assigning the list ((), 4) to @lines and nothing to $num.  Perhaps you
 meant:
 
 my ( $num, @lines ) = ( 4, () );
 
 Or simply:
 
 my ( $num, @lines ) = 4;

Indeed, good catch.

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




Re: Interpolation Problem with Matching

2005-03-08 Thread John W. Krahn
RICHARDS, JIM wrote:
I am trying to compare files names listed in a file to the actual files
in a directory.  My code is as follows:
Your code won't compile.  Please add the following two lines:
use warnings;
use strict;
to the top of your program and let perl help you find the mistakes.
The best bet to solve your problem is to use a hash for the file names, 
something like:

my $filelist = '/home/jim/filelist';
open FILES, '', $filelist or die Cannot open $filelist: $!;
my %files;
while ( FILES ) {
chomp;
$files{ $_ }++;
}
close FILES;
my $dir = '/home/jim/somedir';
opendir DIR, $dir or die Cannot open $dir: $!;
while ( my $file = readdir DIR ) {
if ( exists $files{ $file } ) {
print $file\n;
}
}
closedir DIR;

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: tricky hash

2005-03-08 Thread John W. Krahn
Ing. Branislav Gerzo wrote:
Hello beginners@perl.org,
Hello,
anyone could me help with:
use strict;
use warnings;
my %kw = ();
my $kw = \%kw;
for my $cat (split(/\//, 'something/other/foo/bar')) { $kw-{cnt}++; 
$kw-{cat${kw-{cnt}}} = $cat }
I get: Can't use bareword (kw) as a HASH ref while strict refs in
use..
The goal is to get something like:
$kw-{cat1} = 'something',
$kw-{cat2} = 'other',
$kw-{cat3} = 'foo',
$kw-{cat4} = 'bar'
anyone?
my $string = 'something/other/foo/bar';
my $count;
my $kw = { map { 'cat' . ++$count, $_ } split /\//, $string };

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: tricky hash

2005-03-08 Thread Ing. Branislav Gerzo
John W. Krahn [JWK], on Tuesday, March 08, 2005 at 12:58 (-0800) made
these points:

JWK my $string = 'something/other/foo/bar';
JWK my $count;
JWK my $kw = { map { 'cat' . ++$count, $_ } split /\//, $string };

this is really tricky reply I awaited, I like this solution, really
nice. Also, in my case, the best is:

use strict;
use warnings;
use Data::Dumper ;

my %kw = ();
my $kw = \%kw;
$kw = { map { 'cat' . ++$kw-{cnt}, $_ } split /\//, 'something/other/foo/bar' 
};
print Dumper $kw;

__END__
$VAR1 = {
  'cat2' = 'other',
  'cat3' = 'foo',
  'cat1' = 'something',
  'cat4' = 'bar'
};

Interesting on this is, $kw-{cnt} doesn't exist :)

Thanks to all who replied!

-- 

 ...m8s, cu l8r, Brano.

[Is a white person from Africa an African-American?]



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




Counting Multiple lines of data with a unique column of information

2005-03-08 Thread Wilson, Josh --- Systems Analyst --- GO
I have a scenario in which palettes are weighed prior to delivery and
then that data is submitted to a server.  Once the data is transferred,
I have to parse a batch file and strip out information for each shipment
number and format it for print.  

The problem is that one shipment might have more than one palette and I
don't know how to strip multiple lines of data (with a unique shipment
number) for processing.  I'm using Active Perl 5.8 in a Windows
environment.

For Example here are a few lines of dummy data
(header provided for information only):

ShipmentNumber  Weight  Date  Time  LocationID

01000 254 03082005 11:25:21 500
01000 210 03082005 11:27:36 500
01401 112 03082005 11:35:21 500
01401 678 03082005 11:37:36 500
01002 450 03082005 17:54:00 001
01785 105 03082005 03:05:67 250


I need to be able to parse this data and know that shipment #01000 has 2
pallets, that shipment #01401 has 2 pallets, that shipment #01002 has
only 1 pallet, and so on...

I also need to know which shipment # belongs to which locationid.

I think I know how to perform every task necessary with the exception of
knowing how many pallets are with each shipment #.

Any ideas?




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




mail question

2005-03-08 Thread Amy Kline
Hi,
How do I modify the following code to email a file (textfile.txt) to
[EMAIL PROTECTED]

open (MAIL, |/usr/bin/mail [EMAIL PROTECTED]);
print MAIL Subject: test;
print MAIL This is a test;
close MAIL;

The above code works fine but instead of sending the text - This is a
test, I would like to send a file, textfile.txt.

thanks.

amy

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




Re: Counting Multiple lines of data with a unique column of information

2005-03-08 Thread John W. Krahn
Wilson, Josh --- Systems Analyst --- GO wrote:
I have a scenario in which palettes are weighed prior to delivery and
then that data is submitted to a server.  Once the data is transferred,
I have to parse a batch file and strip out information for each shipment
number and format it for print.  

The problem is that one shipment might have more than one palette and I
don't know how to strip multiple lines of data (with a unique shipment
number) for processing.  I'm using Active Perl 5.8 in a Windows
environment.
For Example here are a few lines of dummy data
(header provided for information only):
ShipmentNumber  Weight  Date  Time  LocationID
01000 254 03082005 11:25:21 500
01000 210 03082005 11:27:36 500
01401 112 03082005 11:35:21 500
01401 678 03082005 11:37:36 500
01002 450 03082005 17:54:00 001
01785 105 03082005 03:05:67 250
I need to be able to parse this data and know that shipment #01000 has 2
pallets, that shipment #01401 has 2 pallets, that shipment #01002 has
only 1 pallet, and so on...
I also need to know which shipment # belongs to which locationid.
I think I know how to perform every task necessary with the exception of
knowing how many pallets are with each shipment #.
Any ideas?
Off the top of my head (and untested.)
my %locations;
my %pallets;
while ( FILE ) {
my ( $ShipmentNumber, $LocationID ) = ( split )[ 0, -1 ];
$pallets{ $ShipmentNumber }++;
push @{ $locations{ $LocationID } }, $ShipmentNumber;
}
for my $ShipmentNumber ( keys %pallets ) {
print $Shipment Number $ShipmentNumber has $pallets{$ShipmentNumber} 
pallets.\n;
}

for my $LocationID ( keys %locations ) {
print $Location ID $LocationID shipped to @{$locations{$LocationID}}.\n;
}

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: Counting Multiple lines of data with a unique column of information

2005-03-08 Thread Willy West
forgot to reply to all for the following *laugh*



-- Forwarded message --
From: Willy West [EMAIL PROTECTED]
Date: Tue, 8 Mar 2005 19:20:24 -0500
Subject: Re: Counting Multiple lines of data with a unique column of information
To: Wilson, Josh --- Systems Analyst --- GO [EMAIL PROTECTED]



 The problem is that one shipment might have more than one palette and I
 don't know how to strip multiple lines of data (with a unique shipment
 number) for processing.  I'm using Active Perl 5.8 in a Windows
 environment.

 For Example here are a few lines of dummy data
 (header provided for information only):

 ShipmentNumber  Weight  Date  Time  LocationID

 01000 254 03082005 11:25:21 500
 01000 210 03082005 11:27:36 500
 01401 112 03082005 11:35:21 500
 01401 678 03082005 11:37:36 500
 01002 450 03082005 17:54:00 001
 01785 105 03082005 03:05:67 250

here is one way to do it:

use strict;
use warnings;

my @data =
(
01000 254 03082005 11:25:21 500,
01000 210 03082005 11:27:36 500,
01401 112 03082005 11:35:21 500,
01401 678 03082005 11:37:36 500,
01002 450 03082005 17:54:00 001,
01785 105 03082005 03:05:67 250
);

my $storage;

#replace the for loop with a
# while(FILEHANDLE) to get the results from an open file :)
#you may want to add chomp(); to the mix as
#well.

for (@data){
print one line is $_\n;

/(\d{5})(.*)/; #assumes a 5 digit part #

push (@{$storage-{$1}},$2);

#this last bit puts the data into a hash that
#uses the part numbers as its keys..

}

for (keys(%{$storage})){
print Item $_ has  . @{$storage-{$_}} .   entries\n;
}



and here is the sample data's output::

one line is 01000 254 03082005 11:25:21 500
one line is 01000 210 03082005 11:27:36 500
one line is 01401 112 03082005 11:35:21 500
one line is 01401 678 03082005 11:37:36 500
one line is 01002 450 03082005 17:54:00 001
one line is 01785 105 03082005 03:05:67 250
Item 01000 has 2 entries
Item 01401 has 2 entries
Item 01785 has 1 entries
Item 01002 has 1 entries

--

look up regular expressions with perl and hash references in order
to make these
kinds of tasks easier.

good luck :)

Willy
http://www.hackswell.com/corenth

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




Re: mail question

2005-03-08 Thread Peter Rabbitson
As stated earlier on the list I believe, I would not use an external program 
call. Instead use the MIME::Lite - clean and simple:

my $mail = MIME::Lite-new (From = $from_email,
To = $to_email,
Subject = 'Test',
Type ='multipart/mixed'
);

$mail-attach ( Disposition = 'attachment',
Path = '/tmp/file1.txt'
);

$mail-attach ( Disposition = 'attachment',
Path = '/tmp/file2.txt'
);

$mail-attach ( Disposition = 'inline',
Data = $inline_text
);

$mail-send ( 'smtp', 'smtp.myisp.com', Timeout=60 );


On Tue, Mar 08, 2005 at 06:05:33PM -0500, Amy Kline wrote:
 Hi,
 How do I modify the following code to email a file (textfile.txt) to
 [EMAIL PROTECTED]
 
 open (MAIL, |/usr/bin/mail [EMAIL PROTECTED]);
 print MAIL Subject: test;
 print MAIL This is a test;
 close MAIL;
 
 The above code works fine but instead of sending the text - This is a
 test, I would like to send a file, textfile.txt.
 
 thanks.
 
 amy
 
 -- 
 To unsubscribe, e-mail: [EMAIL PROTECTED]
 For additional commands, e-mail: [EMAIL PROTECTED]
 http://learn.perl.org/ http://learn.perl.org/first-response
 
 

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




Re: mail question

2005-03-08 Thread Marco Antonio Manzo
Or use the new collection of Email::* modules for handling Mime stuff.

Email::Simple would do the job.


On Tue, 2005-03-08 at 19:53 -0500, Peter Rabbitson wrote:
 As stated earlier on the list I believe, I would not use an external program 
 call. Instead use the MIME::Lite - clean and simple:
 
 my $mail = MIME::Lite-new (  From = $from_email,
   To = $to_email,
   Subject = 'Test',
   Type ='multipart/mixed'
   );
 
 $mail-attach (   Disposition = 'attachment',
   Path = '/tmp/file1.txt'
   );
 
 $mail-attach ( Disposition = 'attachment',
 Path = '/tmp/file2.txt'
 );
 
 $mail-attach ( Disposition = 'inline',
   Data = $inline_text
   );
 
 $mail-send ( 'smtp', 'smtp.myisp.com', Timeout=60 );
 
 
 On Tue, Mar 08, 2005 at 06:05:33PM -0500, Amy Kline wrote:
  Hi,
  How do I modify the following code to email a file (textfile.txt) to
  [EMAIL PROTECTED]
  
  open (MAIL, |/usr/bin/mail [EMAIL PROTECTED]);
  print MAIL Subject: test;
  print MAIL This is a test;
  close MAIL;
  
  The above code works fine but instead of sending the text - This is a
  test, I would like to send a file, textfile.txt.
  
  thanks.
  
  amy
  
  -- 
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  http://learn.perl.org/ http://learn.perl.org/first-response
  
  
 
-- 
Marco Antonio Manzo Bañuelos
[EMAIL PROTECTED]
http://www.unixmonkeys.com/amnesiac/


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




log rotate on multiple files

2005-03-08 Thread DBSMITH
Will someone provide clues as to how use logfile rotate on multiple files?
I looked at the rotate.pm and did not see anything this the code.  I tried
one File = line followed by multipl scalers but that did not work then I
tried multiple File = references and this did not work???

thank you,




Here is my code:

use strict;
use warnings;
use diagnostics;
use MIME::Lite;
use Logfile::Rotate;

$ENV{PATH} = qq(/opt/SUNWsamfs/sbin:/usr/bin:/usr/sbin:/usr/local/log);

my $wd=40;
my $tpexports = qq(/usr/local/log/exports);
my $hrtlabtapeszs = qq(/usr/local/log/heartlab_tapeszs.log);
my $fujitapeszs = qq(/usr/local/log/fuji_tapeszs.log);
my $slhtapeszs = qq(/usr/local/log/slh_tapeszs.log);

open (_, +$tpexports) || die could not open file: $tpexports $!;
open (FFF_, +$hrtlabtapeszs) || die could not open file: $hrtlabtapeszs
$!;
open (FF_, +$fujitapeszs) || die could not open file: $fujitapeszs $!;
#open (F_, +$slhtapeszs) || die could not open file: $slhtapeszs $!;



my $logs = new Logfile::Rotate (File = $tpexports,
File = $hrtlabtapeszs,
   Count = 10,
Gzip = '/usr/bin/gzip',
Dir  = '/usr/local/log/old',
Flock = 'yes',
Persist = 'yes' );
$logs-rotate();

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams



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




2 -D arry in perl

2005-03-08 Thread Adam Saeed
hi i am some new to per;.
I want to get a day numbers by year and store them in e a 2 -d array,
getting data from mysql. i.e data[dayofyear][year] BUT I COULD NOT
GETTING THE DESIRE RESULT ... ANY HELP my snap code is:
...
...

@year  #have list of years
my $i=0;
my @dayofyear=([],[]);
my @data=([],[]);
my $old;
for $i (0 .. $yrtot)
{
$old = $dbh-prepare(SELECT
distinct(dayofyear(from_unixtime(datetime))) FROM table where
year(from_unixtime(datetime))='$year[$i]');
  $old-execute();
  while (@dayofyear = $old-fetchrow_array())
{
 push (@data,@dayofyear);
 }
}


Regards,
Adam Saeed
[EMAIL PROTECTED]

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