Re: formatting a list

2013-10-01 Thread Charles DeRykus
On Mon, Sep 30, 2013 at 7:43 AM, Rajeev Prasad  wrote:

> thank you Shawn. this works nicely for me.
>
>
>   --
>  *From:* Shawn H Corey 
> *To:* beginners@perl.org
> *Cc:* Rajeev Prasad 
> *Sent:* Saturday, September 28, 2013 8:49 AM
> *Subject:* Re: formatting a list
>
> On Fri, 27 Sep 2013 22:59:01 -0700 (PDT)
> Rajeev Prasad  wrote:
> ...
>

I'm not bucking for "net nanny" but, while full solutions and follow-on
discussions can be enlightening, I wonder if they're really advantageous to
the OP.  Not to embarrass anyone but there was no mention of DIY attempts,
no soliciting of hints  or approaches, or even mention of  being stuck or
frustrated thinking about how to start.

A  "guru service while you wait " may  be excellent but disciples will fail
to ever get  their G.E.D. (guru equivalency diploma).

-- 
Charles DeRykus


Re: formatting a list

2013-09-30 Thread Rajeev Prasad
thank you Shawn. this works nicely for me.





 From: Shawn H Corey 
To: beginners@perl.org 
Cc: Rajeev Prasad  
Sent: Saturday, September 28, 2013 8:49 AM
Subject: Re: formatting a list
 

On Fri, 27 Sep 2013 22:59:01 -0700 (PDT)
Rajeev Prasad  wrote:

> i want them to look neat, something like this: where they look in
> line. I do not know before hand how long each word would be
> 
> abc124567
> xy4z___xtr4__sdf
> PQRSDR_xcvf__scc234
> 
> how could i use the sprintf to obtain such an effect?

Try:

#!/usr/bin/env perl

use strict;
use warnings;

# --

my @data = ();
my @maxs = ();

while(  ){
  chomp;
  my @fields = split m{ _+ }msx, $_;

  for my $i ( 0 .. $#fields ){
    my $len = length( $fields[$i] );
    if( ( $maxs[$i] || 0 ) < $len ){
      $maxs[$i] = $len;
    }
  }
  push @data, \@fields;
}

for my $row ( @data ){
  my @fields = @$row;
  my $last = pop @fields;
  for my $i ( 0 .. $#fields ){
    my $len = length( $fields[$i] );
    print $fields[$i], '_' x ( $maxs[$i] - $len + 1 );
  }
  print $last, "\n";
}

__DATA__
abc_12_4567
xy4z_xtr4_sdf
PQRSDR_xcvf_scc234


-- 
Don't stop where the ink does.
    Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/

Re: formatting a list

2013-09-28 Thread Shawn H Corey
On Fri, 27 Sep 2013 22:59:01 -0700 (PDT)
Rajeev Prasad  wrote:

> i want them to look neat, something like this: where they look in
> line. I do not know before hand how long each word would be
> 
> abc124567
> xy4z___xtr4__sdf
> PQRSDR_xcvf__scc234
> 
> how could i use the sprintf to obtain such an effect?

Try:

#!/usr/bin/env perl

use strict;
use warnings;

# --

my @data = ();
my @maxs = ();

while(  ){
  chomp;
  my @fields = split m{ _+ }msx, $_;

  for my $i ( 0 .. $#fields ){
my $len = length( $fields[$i] );
if( ( $maxs[$i] || 0 ) < $len ){
  $maxs[$i] = $len;
}
  }
  push @data, \@fields;
}

for my $row ( @data ){
  my @fields = @$row;
  my $last = pop @fields;
  for my $i ( 0 .. $#fields ){
my $len = length( $fields[$i] );
print $fields[$i], '_' x ( $maxs[$i] - $len + 1 );
  }
  print $last, "\n";
}

__DATA__
abc_12_4567
xy4z_xtr4_sdf
PQRSDR_xcvf_scc234


-- 
Don't stop where the ink does.
Shawn

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: formatting a list

2013-09-28 Thread Rob Dixon

On 28/09/2013 06:59, Rajeev Prasad wrote:

hello,

following is obtained by concatenating 3 values using an underscore to
produce a list:

|abc_12_4567
xy4z_xtr4_sdf
PQRSDR_xcvf_scc234|

i want them to look neat, something like this: where they look in line.
I do not know before hand how long each word would be

|abc124567
xy4z___xtr4__sdf
PQRSDR_xcvf__scc234|


how could i use the sprintf to obtain such an effect?


If you prefer, or if there is any possibility that the fields may 
themselves contain spaces, you can build an array of maximum field 
widths and use a bespoke pad subroutine.


Rob

use strict;
use warnings;

use List::Util 'max';

my @data = (
  [qw/ abc 12 4567 /],
  [qw/ xy4z xtr4 sdf /],
  [qw/ PQRSDR xcvf scc234 /],
);

my @widths;
for my $i (0.. $#{$data[0]}) {
  push @widths, max map length($_->[$i]), @data;
}

for my $row (@data) {
  my $line;
  $line .= pad($row->[$_], 1+$widths[$_]) for 0 .. $#$row-1;
  $line .= $row->[-1];
  print $line, "\n";
}

sub pad {
  my ($string, $length) = @_;
  for ($length - length $string) {
$string .= '_' x $_ if $_ > 0;
  }
  $string;
}

**output**

abc12___4567
xy4z___xtr4_sdf
PQRSDR_xcvf_scc234


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: formatting a list

2013-09-28 Thread Rob Dixon

On 28/09/2013 06:59, Rajeev Prasad wrote:

hello,

following is obtained by concatenating 3 values using an underscore to
produce a list:

|abc_12_4567
xy4z_xtr4_sdf
PQRSDR_xcvf_scc234|

i want them to look neat, something like this: where they look in line.
I do not know before hand how long each word would be

|abc124567
xy4z___xtr4__sdf
PQRSDR_xcvf__scc234|


how could i use the sprintf to obtain such an effect?


You could build a format into a separate variable, using the maximum
length of each column as the field size.

Because sprintf will pad only with spaces (or zeroes) you need to
transliterate once the lines are built.

This program demonstrates. Note that the statement modifier

for 1 + max map length($_->[$i]), @data;

doesn't loop at all: it just serves to contextualize the calculation
into $_.

Rob


use strict;
use warnings;

use List::Util 'max';

my @data = (
  [qw/ abc 12 4567 /],
  [qw/ xy4z xtr4 sdf /],
  [qw/ PQRSDR xcvf scc234 /],
);

my $format;
for my $i (0.. $#{$data[0]}-1) {
  $format .= "%-${_}s" for 1 + max map length($_->[$i]), @data;
}
$format .= "%s\n";

for my $row (@data) {
  (my $line = sprintf $format, @$row) =~ tr/ /_/;
  print $line;
}

**output**

abc12___4567
xy4z___xtr4_sdf
PQRSDR_xcvf_scc234


--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: formatting a list

2013-09-28 Thread Shlomi Fish
Hi Jing,

On Sat, 28 Sep 2013 16:53:20 +0800
Logust Yu  wrote:

> Hi Rajeev,
> I guess you can use printf to print them into strings, and then replace the
> spaces with underscores.
> 

The problem with using sprintf and a replace operation like that, like you
suggest is that it won't handle trailing spaces in the strings properly.

E.g:

1. "hello"  ==> "hello___" .

2. "hello " ==> "hello___" .

I'm not sure whether this is an issue, but in any case, I believe the function
I demonstrated would be easier.

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
The Case for File Swapping - http://shlom.in/file-swap

“We’re not doing it for money… we’re doing it for a shitload of money!”
— Spaceballs, http://www.imdb.com/title/tt0094012/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: formatting a list

2013-09-28 Thread Logust Yu
ofc it should be "sprintf"...


2013/9/28 Rajeev Prasad 

> hello,
>
> following is obtained by concatenating 3 values using an underscore to
> produce a list:
>
> abc_12_4567
> xy4z_xtr4_sdf
> PQRSDR_xcvf_scc234
>
> i want them to look neat, something like this: where they look in line. I
> do not know before hand how long each word would be
>
> abc124567
> xy4z___xtr4__sdf
> PQRSDR_xcvf__scc234
>
>
> how could i use the sprintf to obtain such an effect?
>
> ty.
>


Re: formatting a list

2013-09-28 Thread Logust Yu
Hi Rajeev,
I guess you can use printf to print them into strings, and then replace the
spaces with underscores.

Regards,
Jing


2013/9/28 Rajeev Prasad 

> hello,
>
> following is obtained by concatenating 3 values using an underscore to
> produce a list:
>
> abc_12_4567
> xy4z_xtr4_sdf
> PQRSDR_xcvf_scc234
>
> i want them to look neat, something like this: where they look in line. I
> do not know before hand how long each word would be
>
> abc124567
> xy4z___xtr4__sdf
> PQRSDR_xcvf__scc234
>
>
> how could i use the sprintf to obtain such an effect?
>
> ty.
>


Re: formatting a list

2013-09-27 Thread Shlomi Fish
Hi Rajeev,

On Fri, 27 Sep 2013 22:59:01 -0700 (PDT)
Rajeev Prasad  wrote:

> hello,
> 
> following is obtained by concatenating 3 values using an underscore to
> produce a list:
> 
> abc_12_4567
> xy4z_xtr4_sdf
> PQRSDR_xcvf_scc234
> i want them to look neat, something like this: where they look in line. I do
> not know before hand how long each word would be
> 
> abc124567
> xy4z___xtr4__sdf
> PQRSDR_xcvf__scc234
> 
> how could i use the sprintf to obtain such an effect?
> 

I don't think sprintf can pad with underscores, but you can use the following
function (untested):


sub pad_with_underscores
{
my ($str, $len) = @_;

return $str . ('_' x ($len - length($str)));
}


Maybe this can also be done with https://metacpan.org/module/Text::Table (which
I should note that I maintain).

Regards,

Shlomi Fish

-- 
-
Shlomi Fish   http://www.shlomifish.org/
Apple Inc. is Evil - http://www.shlomifish.org/open-source/anti/apple/

http://en.wikipedia.org/wiki/Evil redirects to XSLT.
— http://www.shlomifish.org/humour/bits/facts/XSLT/

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Formatting Numbers

2012-02-12 Thread Mike Blezien
Thank you Rob this helps allot and should do the trick.


Mike(mickalo)Blezien
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Thunder Rain Internet Publishing
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
  - Original Message - 
  From: Rob Dixon 
  To: Perl Beginners 
  Cc: Mike Blezien 
  Sent: Sunday, February 12, 2012 10:46 AM
  Subject: Re: Formatting Numbers


  On 12/02/2012 16:14, Mike Blezien wrote:
  >
  > Need a little assistance formatting numbers pulled from a databaes. Many
  > are like this:
  >
  > 179550, 45960, 890458 etc.
  >
  > what I need to do is format these values with a comma so they look like
  > this:
  >
  > 179,550, 45,960, 890,458
  >
  > What is the easiest way to do this?

  Hi Mike

  I suggest the subtitution s/(\d+?)(?=(\d{3})+\b)/$1,/g which looks for
  all sequences of digits that are followed by a multiple of three digits
  and puts a comma after each of them. The program below illustrates this.

  HTH,

  Rob


  use strict;
  use warnings;

  for (qw/ 179550 45960 890458 -12345678 1/) {
 (my $n = $_) =~ s/(\d+?)(?=(\d{3})+\b)/$1,/g;
 print "$n\n";
  }

  **OUTPUT**

  179,550
  45,960
  890,458
  -12,345,678
  1,000,000,000,000


Re: Formatting Numbers

2012-02-12 Thread Rob Dixon

On 12/02/2012 16:14, Mike Blezien wrote:


Need a little assistance formatting numbers pulled from a databaes. Many
are like this:

179550, 45960, 890458 etc.

what I need to do is format these values with a comma so they look like
this:

179,550, 45,960, 890,458

What is the easiest way to do this?


Hi Mike

I suggest the subtitution s/(\d+?)(?=(\d{3})+\b)/$1,/g which looks for
all sequences of digits that are followed by a multiple of three digits
and puts a comma after each of them. The program below illustrates this.

HTH,

Rob


use strict;
use warnings;

for (qw/ 179550 45960 890458 -12345678 1/) {
  (my $n = $_) =~ s/(\d+?)(?=(\d{3})+\b)/$1,/g;
  print "$n\n";
}

**OUTPUT**

179,550
45,960
890,458
-12,345,678
1,000,000,000,000

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Formatting Numbers

2012-02-12 Thread Shlomi Fish
Hi Mike,

On Sun, 12 Feb 2012 10:14:42 -0600
"Mike Blezien"  wrote:

> Hello,
> 
> Need a little assistance formatting numbers pulled from a databaes. Many are 
> like this:
> 
> 179550, 45960, 890458 etc.
> 
> what I need to do is format these values with a comma so they look like this:
> 
> 179,550, 45,960, 890,458
> 
> What is the easiest way to do this?
> 

See:

http://perldoc.perl.org/perlfaq5.html#How-can-I-output-my-numbers-with-commas-added%3f

A CPAN search yields https://metacpan.org/module/Number::Format , but that may
be an overkill for you because it provides everything except the kitchen sink.

Regards,

Shlomi Fish


-- 
-
Shlomi Fish   http://www.shlomifish.org/
Understand what Open Source is - http://shlom.in/oss-fs

The bad thing about hardware is that it sometimes works and it sometimes
doesn’t. The good thing about software is that it’s consistent: it always 
does not work, and it always does not work in exactly the same way.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/




Re: Formatting Question

2008-09-16 Thread John W. Krahn

[EMAIL PROTECTED] wrote:

Hello


Hello,


I am sure the answer to this question is very simple. I have a number
value which I am inserting into a string I am building. How can I
append the number into the string so that it will always be 2
characters in length? In other words if the month is 9, how can I make
it appear as "09"?


For date strings you could use the POSIX::strftime function.

perldoc POSIX



John
--
Perl isn't a toolbox, but a small machine shop where you
can special-order certain sorts of tools at low cost and
in short order.-- Larry Wall

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




Re: Formatting Question

2008-09-16 Thread Dermot
2008/9/17  <[EMAIL PROTECTED]>:
> Hello
>
> I am sure the answer to this question is very simple. I have a number value 
> which I am inserting into a string I am building. How can I append the number 
> into the string so that it will always be 2 characters in length? In other 
> words if the month is 9, how can I make it appear as "09"?
>

I was stuggling with this. Thanx Shawn I had %2d and was reading
through sprintf.

#!/usr/bin/perl

use strict;
use warnings;

my @nums = (1..12);
for (@nums) {
printf("%02d\n", $_, 0);
}

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




Re: Formatting Question

2008-09-16 Thread Mr. Shawn H. Corey
On Tue, 2008-09-16 at 17:32 -0700, [EMAIL PROTECTED] wrote:
> Hello
> 
> I am sure the answer to this question is very simple. I have a number value 
> which I am inserting into a string I am building. How can I append the number 
> into the string so that it will always be 2 characters in length? In other 
> words if the month is 9, how can I make it appear as "09"?
> 
> Thanks,
> Andrew
> 

$string = sprintf( '%02d', $number );

See `perldoc -f sprintf` for details.


-- 
Just my 0.0002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."
Cross Time Cafe

"Perl is the duct tape of the Internet."
Hassan Schroeder, Sun's first webmaster


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




Re: Formatting output after search and replace

2008-04-29 Thread Chas. Owens
On Tue, Apr 29, 2008 at 6:06 PM, melody <[EMAIL PROTECTED]> wrote:
snip
>  #!/usr/bin/perl
>  use warnings;
>  use strict;
snip

Good, keep this up

snip
>  my @array;
>  my @replacearray;
snip

Try to declare your variables where you initialize them.

snip
>  open FHR,'<',"repl.txt";
>  open OUT,'>>',"output.txt";
>  open IN,'<',"input.txt";
snip

Good use of the three argument version of open, but you should be
using lexical filehandles and checking for errors:

open my $fhr, "<", "repl.txt"
or die "could not open repl.txt: $!";

Also, it is customary to write Perl programs as filters, that is they
work on data presented on STDIN or provided on the command line* and
print their results to STDOUT (with errors going to STDERR).  This
makes the program very flexible and cuts out a lot of file opening
code.

snip
>  @replacearray=;
>  @array=;
>  for my $i(0..$#array)
snip

Unless you are certain that your files are small this is an incredibly
bad idea.  Use a while loop instead.  Also, don't use subscripts when
you can use the iterator version of for:

for my $value (@array) {
#changes to $value also occur to $array[current position] through
the magic of aliasing
}

>  {
>   $array[$i]=~s/to be replaced/$replacearray[0]/gi;
>   push @replacearray, shift @replacearray;
>  }
>  my @result=grep(/[^\$]/,@array);
>  print OUT @result;
>
>
>  Can anyone point out to me what i am doing wrong??Thanks
snip

Off hand I would say that your problem is the newlines on both the
replace and the input lines.  You start with

"Text| to be replaced\n" and "replace1\n" and perform a substitution
that results in "Text| replace1\n\n".  The solution is to chomp the
replace lines as they are being read in:

my @replace = map { chomp; $_ } <$fhr>;

Here is my version of your code (note:  would be <> and you
wouldn't use the string/filehandle trick, they are there to make the
program self-contained for list purposes):

#!/usr/bin/perl

use strict;
use warnings;

my $replacefile = "replace1\nreplace2\nreplace3\n";

open my $fh, "<", \$replacefile
or die "could not open the scalar \$replacefile as a file: $!";

my @replace = map { chomp; $_ } <$fh>;

while () {
s/to be replaced/$replace[0]/gi;
print;
push @replace, shift @replace;
}

__DATA__
Text| to be replaced
Text| to be replaced
Text| to be replaced
Text| to be replaced
Text| to be replaced


* happily an empty <> exhibits this behavior (using STDIN if @ARGV is
empty or auto-opening the files in @ARGV if they are present)

-- 
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.

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




Re: formatting a string

2007-07-04 Thread Mumia W.

On 07/03/2007 08:32 PM, Joseph L. Casale wrote:

I have an array with the following data in it:

/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/AN-DC 
(Win2003 Ent x64).vmx
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
1.vmdk
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
2.vmdk

I always deal with indices' 1 through to the end in the function in question, so it's easy to get 
the second indices (First disc) and so on. I need to manipulate the path though now, I am wanting 
to search for *all* the text following the third "/" and before the fourth "/" 
and replace it with a string variable. So far, this is seeming to be way over my current capacity :)

Can anyone point me to the topic/method I should use so I may read up on build 
this myself?

Thanks!
jlc





File::Spec->splitdir will let you split the string into directories 
which you can manipulate individually.


Or you can just use the split function to split on "/".

Good luck.




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




RE: formatting a string

2007-07-03 Thread Prabu Ayyappan
Read Perl reqular expression and search replace.
   
  $perldoc perlretut
   
  http://search.cpan.org/~nwclark/perl-5.8.8/pod/perlretut.pod

"Joseph L. Casale" <[EMAIL PROTECTED]> wrote:
v\:* {behavior:url(#default#VML);}  o\:* {behavior:url(#default#VML);}  
w\:* {behavior:url(#default#VML);}  .shape {behavior:url(#default#VML);}
Yup, lol…
Wish I understood this! What is the line that does the search called? What do I 
look up to read up on this?
  Thanks!
jlc
   
From: Prabu Ayyappan [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, July 03, 2007 10:55 PM
To: Joseph L. Casale; beginners@perl.org
Subject: Re: formatting a string

   
A quick solutionMay be you can enhance it more as you like..

 

@discarr = ('/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC 
(Win2003 Ent x64)/AN-DC (Win2003 Ent 
x64).vmx','/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent 
x64)/Disc 1.vmdk','/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC 
(Win2003 Ent  x64)/Disc 2.vmdk');

$replace = "REPLACESTRING";

foreach $disc(@discarr){
  print "Before $disc \n";
  $disc =~ s/\/vmfs\/volumes\/(.*?)\//\/vmfs\/volumes\/$replace\//gi;
  print "After $disc \n";
}

 

Hope this helps.

 

Thanks,

Prabu.M.A
"Joseph L. Casale" <[EMAIL PROTECTED]> wrote:

I have an array with the following data in it:

/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/AN-DC 
(Win2003 Ent x64).vmx
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
1.vmdk
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
2.vmdk

I always deal with indices' 1 through to the end in the function in question, 
so it's easy to get the second indices (First disc) and so on. I need to 
manipulate the path though now, I am wanting to search for *all* the text 
following the third "/" and before the fourth "/" and replace it with a string 
variable. So far, this is seeming to be way over my current capacity :)

Can anyone point me to the topic/method I should use so I may read up on build 
this myself?

Thanks!
jlc


   


-
  
  The fish are biting.
Get more visitors on your site using Yahoo! Search Marketing. 



   
-
Get the Yahoo! toolbar and be alerted to new email wherever you're surfing. 

RE: formatting a string

2007-07-03 Thread Joseph L. Casale
Yup, lol...
Wish I understood this! What is the line that does the search called? What do I 
look up to read up on this?
Thanks!
jlc

From: Prabu Ayyappan [mailto:[EMAIL PROTECTED]
Sent: Tuesday, July 03, 2007 10:55 PM
To: Joseph L. Casale; beginners@perl.org
Subject: Re: formatting a string

A quick solutionMay be you can enhance it more as you like..

@discarr = ('/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 
Ent x64)/AN-DC (Win2003 Ent 
x64).vmx','/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent 
x64)/Disc 1.vmdk','/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC 
(Win2003 Ent  x64)/Disc 2.vmdk');
$replace = "REPLACESTRING";
foreach $disc(@discarr){
  print "Before $disc \n";
  $disc =~ s/\/vmfs\/volumes\/(.*?)\//\/vmfs\/volumes\/$replace\//gi;
  print "After $disc \n";
}

Hope this helps.

Thanks,
Prabu.M.A
"Joseph L. Casale" <[EMAIL PROTECTED]> wrote:
I have an array with the following data in it:

/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/AN-DC 
(Win2003 Ent x64).vmx
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
1.vmdk
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
2.vmdk

I always deal with indices' 1 through to the end in the function in question, 
so it's easy to get the second indices (First disc) and so on. I need to 
manipulate the path though now, I am wanting to search for *all* the text 
following the third "/" and before the fourth "/" and replace it with a string 
variable. So far, this is seeming to be way over my current capacity :)

Can anyone point me to the topic/method I should use so I may read up on build 
this myself?

Thanks!
jlc






The fish are biting.
Get more 
visitors<http://us.rd.yahoo.com/evt=49679/*http:/searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50>
 on your site using Yahoo! Search 
Marketing.<%0d%0ahttp:/us.rd.yahoo.com/evt=49679/*http:/searchmarketing.yahoo.com/arp/sponsoredsearch_v2.php?o=US2140&cmp=Yahoo&ctv=Q107Tagline&s=Y&s2=EM&b=50>




Re: formatting a string

2007-07-03 Thread Prabu Ayyappan
A quick solutionMay be you can enhance it more as you like..
   
  @discarr = ('/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 
Ent x64)/AN-DC (Win2003 Ent 
x64).vmx','/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent 
x64)/Disc 1.vmdk','/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC 
(Win2003 Ent  x64)/Disc 2.vmdk');
  $replace = "REPLACESTRING";
  foreach $disc(@discarr){
  print "Before $disc \n";
  $disc =~ s/\/vmfs\/volumes\/(.*?)\//\/vmfs\/volumes\/$replace\//gi;
  print "After $disc \n";
}
   
  Hope this helps.
   
  Thanks,
  Prabu.M.A
"Joseph L. Casale" <[EMAIL PROTECTED]> wrote:
  I have an array with the following data in it:

/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/AN-DC 
(Win2003 Ent x64).vmx
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
1.vmdk
/vmfs/volumes/467f06a5-7d59c067-35cb-0007e9153886/AN-DC (Win2003 Ent x64)/Disc 
2.vmdk

I always deal with indices' 1 through to the end in the function in question, 
so it's easy to get the second indices (First disc) and so on. I need to 
manipulate the path though now, I am wanting to search for *all* the text 
following the third "/" and before the fourth "/" and replace it with a string 
variable. So far, this is seeming to be way over my current capacity :)

Can anyone point me to the topic/method I should use so I may read up on build 
this myself?

Thanks!
jlc




 
-
The fish are biting.
 Get more visitors on your site using Yahoo! Search Marketing.

Re: formatting a string

2007-07-03 Thread Tom Phoenix

On 7/3/07, Joseph L. Casale <[EMAIL PROTECTED]> wrote:


I always deal with indices' 1 through to the end in the function in question,
so it's easy to get the second indices (First disc) and so on.


Huh?


I need to manipulate the path though now, I am wanting to search
for *all* the text following the third "/" and before the fourth "/" and
replace it with a string variable.


That sounds almost as if you're wanting to use substr and index: index
to locate each "/", and substr to work with the identified part of the
string.

Or maybe you want to use a substitution (s///), but I doubt that.

But if you're really manipulating file and directory names, probably a
solution involving (say) File::Basename or another module would be
more likely to be correct.

Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Formatting/presenting regex

2007-01-03 Thread John W. Krahn
Owen wrote:
> I have this regex to look at an Apache log.
> 
> m/^(\S+) \S+ \S+ \[(\d{2})\/(\S+)\/(\d{4}):.+\] "(\w+) (\S+)
> ([^"]+)" (\d{3}) (\d+|-) ".+"$/;
> 
> Would like to set it out in a bit more readable form a la Perl Cook Book and 
> others
> 
> eg
> 
> m/
> ^(\S+)# Comment
>  \S+  # Comment
>  \S+  # Comment
> 
> etc,
> 
> but "they don't work" and I suspect it is something to do with the spaces 
> between
> the elements. I have even tried specifying spaces with \s
> 
> Can someone give me a pointer as to how to go about this. 

$ perl -le'
print
$1
if
"one two three four"
=~
/
^ # start of line
(
\S+   # capture one or more non-whitespace
)
\ # a single space character
\S+   # match one or more non-whitespace
[ ]   # a single space character
\S+   # match one or more non-whitespace
\ # a single space character
/x
'
one




John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

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




Re: Formatting/presenting regex

2007-01-03 Thread Wiggins d'Anconia

Owen wrote:

I have this regex to look at an Apache log.



There are modules to help with that task on CPAN.


m/^(\S+) \S+ \S+ \[(\d{2})\/(\S+)\/(\d{4}):.+\] "(\w+) (\S+)
([^"]+)" (\d{3}) (\d+|-) ".+"$/;

Would like to set it out in a bit more readable form a la Perl Cook Book and 
others

eg

m/
^(\S+)  # Comment
 \S+# Comment
 \S+# Comment

etc,

but "they don't work" and I suspect it is something to do with the spaces 
between the elements. I have even tried specifying spaces with \s



The key is to use the /x modifier on the end of the regex to allow this 
type of formatting. You then, according to perldoc perlretut, can either 
backslash "real" spaces or put them in a character class. See,


perldoc perlretut

for more.



Can someone give me a pointer as to how to go about this. 



HTH,

http://danconia.org





TIA


Owen  



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




Re: Formatting Question

2006-01-04 Thread Tom Phoenix
On 1/4/06, [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:
> Let's say I have the following numbers and I want to print them out so they
> are formatted in money terms:

Have you seen this sub? It's from p. 184 of the llama book (Learning
Perl, 4th ed.).

 sub big_money {
my $number = sprintf "%.2f", shift @_;
# Add one comma each time through the do-nothing loop
1 while $number =~ s/^(-?\d+)(\d\d\d)/$1,$2/;
# Put the dollar sign in the right place
$number =~ s/^(-?)/$1\$/;
$number;
  }

That turns 12345678.9 into "$12,345,678.90". Hope this helps!

--Tom Phoenix
Stonehenge Perl Training

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




Re: Formatting Question

2006-01-04 Thread Jeremy Vinding

[EMAIL PROTECTED] wrote:

Hello,
 
Here's my question.
 
Let's say I have the following numbers and I want to print them out so they  
are formatted in money terms:
 
examples:
 
10834.00

1939432.00
 
 
to print out as:
 
$10,834.00

$1,939,432.00
 
How can I do this? I was suspecting that the "printf" or "sprintf"  functions 
may accomplish this.  But I was not able to figure it out.   I was thinking 
that I may have to build some kind of subroutine to accomplish  this but I was 
hoping there would simpler way. Can anyone help me?
 
Thanks in advance.




$ perldoc -q "numbers with commas"

   How can I output my numbers with commas added?

   This subroutine will add commas to your number:

   sub commify {
  local $_  = shift;
  1 while s/^([-+]?\d+)(\d{3})/$1,$2/;
  return $_;
  }

   This regex from Benjamin Goldberg will add commas to numbers:

  s/(^[-+]?\d+?(?=(?>(?:\d{3})+)(?!\d))│\G\d{3}(?=\d))/$1,/g;

...

--jjv

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




Re: formatting text

2005-11-29 Thread Brano Gerzo
Ing. Branislav Gerzo [IBG], on Tuesday, November 29, 2005 at 17:14
(+0100) wrote:


IBG> And I'd like to print:
IBG> |Name: Branislav  |
IBG> |Surname.: Gerzo  |
IBG>   26.^ 80.^

Nothing is tricky, if man want. So:

sub formie {
  print form 
  '|{<<}: {[[[} 
  |',
  {rfill=>'.'}, shift,   {rfill=>' '},  shift;  
}


-- 

 ...m8s, cu l8r, Brano.

[Don't bother with the shrimp baby, daddy's comin' home with the crabs!]



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




Re: formatting text

2005-11-29 Thread Ing. Branislav Gerzo
Jeff 'japhy' Pinyan [JP], on Tuesday, November 29, 2005 at 09:12
(-0500 (EST)) wrote the following:

Jeff, Perl6::Form is so powerful. But I can't find how to properly do
this:

I have values:
('Name','Branislav');
('Surname','Gerzo');

And I'd like to print:
|Name: Branislav  |
|Surname.: Gerzo  |
  26.^ 80.^
   
Could you please help me with this one ? Other I need I already got,
but this one seems tricky for me.

Thanks.

-- 

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

[I wanna get my kicks now before I go.]


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




Re: formatting text

2005-11-29 Thread Ing. Branislav Gerzo
Jeff 'japhy' Pinyan [JP], on Tuesday, November 29, 2005 at 09:12
(-0500 (EST)) thoughtfully wrote the following:

>> I'd like to know if there is module for following:
JP> Yes, Perl6::Form.  It's a Perl 5 implementation of Perl 6's formats.

sometime is better ask, than DIY. Thanks a lot Japhy, this is exactly
what I'm looking for!

Thanks, thanks and again: thanks.

-- 

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

[Windows: At least the disks make nice drink coasters]



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




Re: formatting text

2005-11-29 Thread Jeff 'japhy' Pinyan

On Nov 29, Ing. Branislav Gerzo said:


I'd like to know if there is module for following:


Yes, Perl6::Form.  It's a Perl 5 implementation of Perl 6's formats.


112
12345678901234567890
=== OUT ===
| This is just |
| small sentence   |
| about nothing.   |
=== OUT ===

So, I'd like to define "|" as start and as end, word-wrapped text,
and length of line is lets say "20" chars.


You could use Perl 5's formats, but they're ugly to work with. 
Perl6::Form presents them in a simpler and better fashion.


  use Perl6::Form;

  print form
"| {} |",
   $string
  ;

does what you want.  See the module's documentation for details.

You'll have to download the module from CPAN, since I highly doubt you 
already have it.


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

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




RE: Formatting Variables

2005-10-12 Thread Ryan Frantz


> -Original Message-
> From: Wiggins d'Anconia [mailto:[EMAIL PROTECTED]
> Sent: Wednesday, October 12, 2005 5:31 PM
> To: Ryan Frantz
> Cc: Perl Beginners List
> Subject: Re: Formatting Variables
> 
>  Ryan Frantz wrote:
> > Perlers,
> >
> >
> >
> > Is there are way to format a variable before placing it into an
array or
> > hash?  I have several variables that contain floating point numbers
that
> > I format prior to printing out:
> >
> >
> >
> > my $float = "12.3456";
> >
> > print "%2.1f\n", $float;
> >
> 
> perldoc -f sprintf

Awesome!  Thanks.

> 
> http://danconia.org
> 
> >
> >
> > I'd like to place these scalars into an array for later use/output
in an
> > HTML table and I figured I have to format them before they are
entered
> > in the array.  Is this possible?  Or is there a different/better
> > solution?
> >
> >
> >
> > ry
> >
> >
> >
> >

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




Re: Formatting Variables

2005-10-12 Thread Wiggins d'Anconia
 Ryan Frantz wrote:
> Perlers,
> 
>  
> 
> Is there are way to format a variable before placing it into an array or
> hash?  I have several variables that contain floating point numbers that
> I format prior to printing out:
> 
>  
> 
> my $float = "12.3456";
> 
> print "%2.1f\n", $float;
> 

perldoc -f sprintf

http://danconia.org

>  
> 
> I'd like to place these scalars into an array for later use/output in an
> HTML table and I figured I have to format them before they are entered
> in the array.  Is this possible?  Or is there a different/better
> solution?
> 
>  
> 
> ry
> 
>  
> 
> 

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




RE: formatting problem

2004-10-30 Thread Charles K. Clarkson
[EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote:

: Hi all,
: 
: I have little formatting problem, we have code:
: 
: sub test {
:   $sth = $dbh->prepare_cached(finish;
:   return;
: }

Don't use a HERE doc and pass $dbh into the subroutine.

sub test {
my $dbh = shift;
my $sth = $dbh->prepare_cached(
q(
INSERT
INTO table( ip, port, type, create_date )
VALUES (?,?,?,?)
)
);
$sth->execute( '12.12.12.12', 80, 'proxy', '2002-12-12' );
$sth->finish;
return;
}

HTH,

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


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




Re: formatting problem

2004-10-30 Thread Bob Showalter
Ing. Branislav Gerzo wrote:
Hi all,
I have little formatting problem, we have code:
sub test {
  $sth = $dbh->prepare_cached(finish;
  return;
}
this of course doesn't work, because SQL is not at begining of the
line. I tried:
  $sth = $dbh->prepare_cached(<<"  SQL");
and that works. But could I use regexp for that? something like this:
  $sth = $dbh->prepare_cached(<<\s*SQL);
it is just cosmetic question, but i'd like to know answer
No, you can't use the regex. For more discussion see:
  perldoc -q "Why don't my <
I prefer this construct:
  $sth = $dbh->prepare_cached(q[
 INSERT INTO table (ip, port, type, create_date)
 VALUES (?,?,?,?)
  ]);
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: formatting the loop

2004-02-12 Thread James Edward Gray II
On Feb 12, 2004, at 10:06 AM, Michael S. Robeson II wrote:

On Feb 11, 2004, at 2:55 PM, James Edward Gray II wrote:

[snip]

my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];

If I may, yuck!  This builds up a list of all the A-Za-z characters 
in the string, adds a boat load of extra - characters, trims the 
whole list to the length you want and stuffs all that inside @char.  
It's also receives a rank of "awful", on the James Gray Scale of 
Readability.  ;)
[snip]

Ok, now I understand. I found that my problem was with how the "next" 
command was operating in conjunction with the grouping of characters. 
Ok, making progress.  :-)
Excellent.  I knew we would get there.

Now, about that array slice I have:

my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len - 1];

I know it wastes a lot of memory and makes perl do much extra work. 
However, when I try to replace that line with something like this:
Ah, it's pretty small potatoes to quibble over, really.  I don't think 
it's in any danger of slowing your code significantly or making you buy 
more RAM.

my @char = ( /[a-z]/ig, ( '-' ) x ($len - length) ;

it doesn't work the way I thought it would (gee what a thought). I 
would like to express the code similar to ( '-' ) x ($len - length)
Na, something like this won't work because you won't know the length of 
those characters, until you stick the somewhere.  Length by default 
works on $_, which still contains a big mess of sequence characters and 
whitespace.

I think your big hang up is trying to do it all in one line.  Two or 
three is fine, right?And of course, there's nothing wrong 
with the current solution.  It does work.  You only need to replace it 
if you want to.  There's always more than one way.  Use what you like.

I'll see if I can add a suggestion below...

#!/usr/bin/perl

use warnings;
use strict;
print "Enter the path of the INFILE to be processed:\n";

# For example "rotifer.txt" or "../Desktop/Folder/rotifer.txt"

chomp (my $infile = );

open(INFILE, $infile)
or die "Can't open INFILE for input: $!";
print "Enter in the path of the OUTFILE:\n";

# For example "rotifer_out.txt" or "../Desktop/Folder/rotifer_out.txt"

chomp (my $outfile = );

open(OUTFILE, ">$outfile")
or die "Can't open OUTFILE for input: $!";
print "Enter in the LENGTH you want the sequence to be:\n";
my ( $len ) =  =~ /(\d+)/ or die "Invalid length parameter";
print OUTFILE "R 1 $len\n\n\n\n"; # The top of the file is supposed

$/ = '>';  # Set input operator

while (  ) {
chomp;
next unless s/^\s*(.+)//;  # delete name and place in memory
my $name = $1;   # what ever in memory saved 
as $name
Right here, $_ holds our sequence, plus some junk.  We can just work 
with $_ then, if we want to.

my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len -1];	# take 
only sequence letters and
		# and add '-' to the end
my $sequence = join( ' ', @char);		# turn into scalar

Alternative to the above two lines:

tr/A-Za-z//cd;  # remove junk from $_
$_ .= '-' x ($len - length) if length() < $len;  # add dashes
s/\b|\B/ /g;# space out
$sequence =~ tr/Tt/Uu/;	# convert T's to U's
Then this would become:

tr/Tt/Uu/;

print OUTFILE " $sequence   $name\n";
And this:

print OUTFILE "$_  $name\n";

}

close INFILE;
close OUTFILE;
Hope that helps.

James

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



Re: formatting the loop

2004-02-12 Thread Michael S. Robeson II
On Feb 11, 2004, at 2:55 PM, James Edward Gray II wrote:

[snip]

my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];

If I may, yuck!  This builds up a list of all the A-Za-z characters in 
the string, adds a boat load of extra - characters, trims the whole 
list to the length you want and stuffs all that inside @char.  It's 
also receives a rank of "awful", on the James Gray Scale of 
Readability.  ;)
[snip]

Ok, now I understand. I found that my problem was with how the "next" 
command was operating in conjunction with the grouping of characters. 
Ok, making progress.  :-)

Now, about that array slice I have:

my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len - 1];

I know it wastes a lot of memory and makes perl do much extra work. 
However, when I try to replace that line with something like this:

my @char = ( /[a-z]/ig, ( '-' ) x ($len - length) ;

it doesn't work the way I thought it would (gee what a thought). I 
would like to express the code similar to
( '-' ) x ($len - length)
 because it is easy for me to read and it tells you clearly what is 
going on. However, every time I try to implement something like that I 
get unexpected output or I have to really rewrite the loop.  Which I 
have been unable to troubleshot as you have been seeing. :-)  I think 
the 'length' command it also counting any '\n' characters or something, 
because my out put ends up with different lengths like this when I use 
the ($len - length) way :

 a c u g a c g a g u - - - - - - - -   bob
 a c u g a c u a g c u g - - - - - - -   fred
with this input:

>bob
actgacgagt
>fred
actgactagctg
The reason I went with  /[a-z]/ig is because some sequence data uses 
other letters to denote ambiguity and other things. I guess I can only 
list the letters it uses but I was just lazy and typed in the entire 
range of "a to z".

I will be continuing to work on it but here is the code as it stands 
now (with that awful array slice).

#!/usr/bin/perl

use warnings;
use strict;
print "Enter the path of the INFILE to be processed:\n";

# For example "rotifer.txt" or "../Desktop/Folder/rotifer.txt"

chomp (my $infile = );

open(INFILE, $infile)
or die "Can't open INFILE for input: $!";
print "Enter in the path of the OUTFILE:\n";

# For example "rotifer_out.txt" or "../Desktop/Folder/rotifer_out.txt"

chomp (my $outfile = );

open(OUTFILE, ">$outfile")
or die "Can't open OUTFILE for input: $!";
print "Enter in the LENGTH you want the sequence to be:\n";
my ( $len ) =  =~ /(\d+)/ or die "Invalid length parameter";
print OUTFILE "R 1 $len\n\n\n\n"; # The top of the file is supposed

$/ = '>';  # Set input operator

while (  ) {
chomp;
next unless s/^\s*(.+)//;  # delete name and place in memory
my $name = $1;	 # what ever in memory saved as $name
my @char = ( /[a-z]/ig, ( '-' ) x $len) [0 .. $len -1];	# take only 
sequence letters and
		# and add '-' to the end
my $sequence = join( ' ', @char);		# turn into scalar
$sequence =~ tr/Tt/Uu/;	# convert T's to U's
print OUTFILE " $sequence   $name\n";
}

close INFILE;
close OUTFILE;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: formatting the loop

2004-02-11 Thread James Edward Gray II
On Feb 11, 2004, at 2:35 PM, Michael S. Robeson II wrote:

next unless s/^\s*(\S+)//;
my $name = $1;
Well, if we're reading name to name, the thing right a the beginning 
of our sequence is going to be a name, right?  The above removes the 
name, and saves it for later use.
OK, I think this is were my problem is. That is how does it know that 
the characters as in "bob" or "fred" are the names and not mistaking 
the sequence of letters "agtcaccgatg" to be placed in memory ($name). 
Basically I am reading the following:

next unless s/^\s*(\S+)//;

as "Go to the next line
Not line.  We're not reading lines anymore.  We're reading chunks of 
characters ending in a >, remember?

unless you see a line with zero or more whitespace characters followed 
by one or more non-whitespace characters
Not quite.  ^ matching at the beginning of our chunk, not the beginning 
of a line.  It's "unless you start with zero-or more whitespace 
characters, following by one or more non-white-space characters..."

Those "one or more non-white-space characters" are going to be the name 
at the beginning.  There's also going to be a \n (a whitespace 
character) at the end of that name, to keep it from going into the 
sequence.

and save the non-whitespace characters in memory."
In my English, it reads, "Unless you can rip a name off the front of 
this chunk, skip it."  ;)  So the only time it ever does any skipping, 
is if the whole chunk is whitespace (or nothing), which would keep it 
from finding a name.  I imagine this only skips the very first read, 
which probably won't have anything interesting between the front of the 
file and the first > character.

If this is correct then how can perl tell the difference between the 
lines containing "bob" or "fred" (and put then in memory) and the 
"acgatctagc" (and not put these in memory) because both lines of data 
seem to fit the expression pattern to me. I think it has something to 
do with how perl is reading through the file that makes this work?
Yes, it's reading > to >.  Also, ^ matches at the beginning of a 
string, not a line, by default.

That's why I gave you the paragraph version earlier today.  I thought 
it was a little easier to follow.  ;)

So, there is something I am "missing",  not noticing or realizing here.
Maybe I've been staring at the code for far to long and should take a 
break!  :-)
Definitely.  Have a break.  It clears the mind.  Come back refreshed 
and reread this message until you break through the fog.

Or just ask more questions and I'll try again.  :D

James

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



Re: formatting the loop

2004-02-11 Thread Michael S. Robeson II
See comments below.

On Feb 11, 2004, at 2:55 PM, James Edward Gray II wrote:

On Feb 11, 2004, at 1:27 PM, Michael S. Robeson II wrote:

[snip]

Anyway, though it works great I am having a tough time trying to 
figure out WHY it works.
See comments below, in the code.

[snip]

I think if I can understand the mechanics behind this script it will 
only help me my future understanding of writing PERL scripts.
Perl.  The language you are learning is called Perl, not PERL.  :)

Hehe, thanks. :-)

[snip]

[snip]

$/ = '>';  # Set input operator
Here's most of the magic.  This sets Perl's input separator to a > 
character.  That means that  won't return a sequence of 
characters ending in a \n like it usually does, but a sequence of 
characters ending in a >.  It basically jumps name to name, in other 
words.

while (  ) {
chomp;
chomp() will remove the trailing >.
OK that makes pretty good sense. I understand that now, I hope. See 
next comment.



next unless s/^\s*(\S+)//;
my $name = $1;
Well, if we're reading name to name, the thing right a the beginning 
of our sequence is going to be a name, right?  The above removes the 
name, and saves it for later use.
OK, I think this is were my problem is. That is how does it know that 
the characters as in "bob" or "fred" are the names and not mistaking 
the sequence of letters "agtcaccgatg" to be placed in memory ($name). 
Basically I am reading the following:

next unless s/^\s*(\S+)//;

as "Go to the next line unless you see a line with zero or more 
whitespace characters followed by one or more non-whitespace characters 
and save the non-whitespace characters in memory."  If this is correct 
then how can perl tell the difference between the lines containing 
"bob" or "fred" (and put then in memory) and the "acgatctagc" (and not 
put these in memory) because both lines of data seem to fit the 
expression pattern to me. I think it has something to do with how perl 
is reading through the file that makes this work?

So, there is something I am "missing",  not noticing or realizing here.
Maybe I've been staring at the code for far to long and should take a 
break!  :-)



my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];
If I may, yuck!  This builds up a list of all the A-Za-z characters in 
the string, adds a boat load of extra - characters, trims the whole 
list to the length you want and stuffs all that inside @char.  It's 
also receives a rank of "awful", on the James Gray Scale of 
Readability.  ;)

Yeah, I need to clean that up a bit!

[snip]

-Mike

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



Re: formatting the loop

2004-02-11 Thread Rob Dixon
James Edward Gray II wrote:
>
> > $/ = '>';  # Set input operator
>
> Here's most of the magic.

Exactly. If you don't believe in magic, don't write in Perl:
most people don't.

Rob



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




Re: formatting the loop

2004-02-11 Thread James Edward Gray II
On Feb 11, 2004, at 1:27 PM, Michael S. Robeson II wrote:

[snip]

Anyway, though it works great I am having a tough time trying to 
figure out WHY it works.
See comments below, in the code.

[snip]

I think if I can understand the mechanics behind this script it will 
only help me my future understanding of writing PERL scripts.
Perl.  The language you are learning is called Perl, not PERL.  :)

[snip]

The working script:
_
#!/usr/bin/perl

use warnings;
use strict;
print "Enter the path of the INFILE to be processed:\n";

# For example "rotifer.txt" or "../Desktop/Folder/rotifer.txt"

chomp (my $infile = );

open(INFILE, $infile)
or die "Can't open INFILE for input: $!";
print "Enter in the path of the OUTFILE:\n";

# For example "rotifer_out.txt" or "../Desktop/Folder/rotifer_out.txt"

chomp (my $outfile = );

open(OUTFILE, ">$outfile")
or die "Can't open OUTFILE for input: $!";
print "Enter in the LENGTH you want the sequence to be:\n";
my ( $len ) =  =~ /(\d+)/ or die "Invalid length parameter";
print OUTFILE "R 1 $len\n\n\n\n"; # The top of the file.

$/ = '>';  # Set input operator
Here's most of the magic.  This sets Perl's input separator to a > 
character.  That means that  won't return a sequence of 
characters ending in a \n like it usually does, but a sequence of 
characters ending in a >.  It basically jumps name to name, in other 
words.

while (  ) {
chomp;
chomp() will remove the trailing >.

next unless s/^\s*(\S+)//;
my $name = $1;
Well, if we're reading name to name, the thing right a the beginning of 
our sequence is going to be a name, right?  The above removes the name, 
and saves it for later use.

my @char = ( /[a-z]/ig, ( '-' ) x $len )[ 0 .. $len - 1 ];
If I may, yuck!  This builds up a list of all the A-Za-z characters in 
the string, adds a boat load of extra - characters, trims the whole 
list to the length you want and stuffs all that inside @char.  It's 
also receives a rank of "awful", on the James Gray Scale of 
Readability.  ;)

my $sequence = join( ' ', @char);
join() the sequence on spaces.

$sequence =~ tr/Tt/Uu/;
Convert formats.

print OUTFILE " $sequence   $name\n";
Send it out.

}

close INFILE;
close OUTFILE;
Hope that helps.

James

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



Re: formatting and syntax

2004-02-11 Thread James Edward Gray II
(redirected to Perl Beginners by James)

On Feb 11, 2004, at 10:34 AM, Michael S. Robeson II wrote:

Hey, thanks again for the perl code.
You're welcome, but let's keep our discussion on the mailing list so we 
can all help and learn.

However, I forgot to take into account that the original input file 
can look one of two ways:
Ah, the old switcheroo.  Gotcha.  

>bob
atcgactagcatcgatcg
acacgtacgactagcac
>fred
actgactacgatcgaca
acgcgcgatacggcat
or (as I posted originally)

>bob
atcgactagcatcgatcgacacgtacgactagcac
>fred
actgactacgatcgacaacgcgcgatacggcat
to be out put as:

R 1 42
 a t c g a c t a g c a t c g a t c g a c a c g t a c g a c t a g c a c 
- - - - - - -   bob
 a c t g a c t a c g a t c g a c a a c g c g c g a t a c g g c a t - - 
- - - - - - -   fred
How about this time I give you the code to parse the two types of input 
and you tie it in with the parts we've already figured out to get the 
right output?  Just shout if you run into more problems.

James

#!/usr/bin/perl

use strict;
use warnings;
local $/ = '';		# use "paragraph mode"

while () {
unless (s/^>(.+?)\s*\n//) {  # find and remove the name
warn "Skipping unknown format:  $_";
next;
}

my $name = $1;  # save name
tr/\n //d;  # join multi-line sequences
print "Name:  $name, Sequence:  $_\n";# show off our progess
}
__DATA__
>bob
atcgactagcatcgatcg
acacgtacgactagcac
>fred
actgactacgatcgaca
acgcgcgatacggcat
>bob
atcgactagcatcgatcgacacgtacgactagcac
>fred
actgactacgatcgacaacgcgcgatacggcat
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



Re: Formatting output

2004-02-10 Thread Jan Eden

Roger Grosswiler wrote:

>hi again, thanks to you, i got it with my date. so 1st point is out. i
>still have a short problem, as i should get my date back in the format
>ddmmyy and i get it in d m y (with %2d, but how to handle in vars)

How about

$lt2mday = sprintf("%02d", $lt2mday);

perldoc -f sprintf

- Jan
-- 
There's no place like ~/

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




Re: formatting and syntax

2004-02-05 Thread Jeff 'japhy' Pinyan
On Feb 5, R. Joseph Newton said:

>my $sequence_length = 20;
>my $line = ;
>chomp $line;
>while ($line) {
>   my $sequence_tag = trim_line($line);
>   $line = ;
>   chomp $line;
>   my @nucleotides = split //, $line;
>   push @nucleotides, '_' for (1..($sequence_length - @nucleotides));

I'd be in favor of:

  push @nucleotides, ('_') x ($sequence_length - @nucleotides);

The 'x' operator on a list returns the list elements repeated the
specified number of times.

>__DATA__
> >bob
>AGTGATGCCGACG
>A G T G A T G C C G A C G _ _ _ _ _ _ _   bob

Ack.  You're mixing the input with the output!

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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




Re: formatting and syntax

2004-02-05 Thread R. Joseph Newton
"Michael S. Robeson II" wrote:

> Hi I am all still to new to PERL and I am having trouble playing with
> formatting my data into a new format. So here is my problem:
>
> I have data (DNA sequence) in a file that looks like this:
>
> 
> # Infile
> 
>  >bob
> AGTGATGCCGACG
>  >fred
> ACGCATATCGCAT
>  >jon
> CAGTACGATTTATC

Good we can see the input structure here.  What jumps out at me is that the
input file comes in pairs of lines.  You will want to structure your input
routine to read and handle the lines by the pair, then.

>
>
> and I need it converted to:
>
> 
> # Outfile
> 
> R 1 20
>
>   A G U G A T G C C G A C G - - - - - - -   bob
>   A C G C A U A U C G C A U - - - - - - -   fred
>   C A G U A C G A U U U A U C - - - - - -   jon

>

[snip-a picture is worth  athousands woprds, and you showed us the picture
above.]

Well we have a fairly simple problem here, I'd say:

Greetings! E:\d_drive\perlStuff\giffy>perl -w
my $sequence_length = 20;
my $line = ;
chomp $line;
while ($line) {
   my $sequence_tag = trim_line($line);
   $line = ;
   chomp $line;
   my @nucleotides = split //, $line;
   push @nucleotides, '_' for (1..($sequence_length - @nucleotides));
   print join(' ', @nucleotides), "   $sequence_tag\n";
   $line = ;
   chomp $line;
}

sub trim_line {
  my $in_line = shift;
  $in_line =~ s/^ >//;
  chomp $in_line;
  return $in_line;
}

__DATA__
 >bob
AGTGATGCCGACG
A G T G A T G C C G A C G _ _ _ _ _ _ _   bob
 >fred
ACGCATATCGCAT
A C G C A T A T C G C A T _ _ _ _ _ _ _   fred
 >jon
CAGTACGATTTATC
C A G T A C G A T T T A T C _ _ _ _ _ _   jon

or, better yet...

Greetings! E:\d_drive\perlStuff\giffy>perl -w
my $sequence_length = 20;
my $line = ;
chomp $line;
while ($line) {
   my $sequence_tag = trim_line($line);
   $line = ;
   chomp $line;
   $line = print_underscore_padded($line, $sequence_length, $sequence_tag);

}


sub trim_line {
  my $in_line = shift;
  $in_line =~ s/^ >//;
  chomp $in_line;
  return $in_line;
}

sub print_underscore_padded {
   my ($line, $sequence_length, $sequence_tag) = @_;
   my @nucleotides = split //, $line;
   push @nucleotides, '_' for (1..($sequence_length - @nucleotides));
   print join(' ', @nucleotides), "   $sequence_tag\n";
   $line = ;
   chomp $line;
   return $line;
}

__DATA__
 >bob
AGTGATGCCGACG
A G T G A T G C C G A C G _ _ _ _ _ _ _   bob
 >fred
ACGCATATCGCAT
A C G C A T A T C G C A T _ _ _ _ _ _ _   fred
 >jon
CAGTACGATTTATC
C A G T A C G A T T T A T C _ _ _ _ _ _   jon


Does that help?

Joseph


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




Re: formatting and syntax

2004-02-04 Thread Jeff 'japhy' Pinyan
On Feb 4, Michael S. Robeson II said:

> >bob
>AGTGATGCCGACG
> >fred
>ACGCATATCGCAT
> >jon
>CAGTACGATTTATC

>R 1 20
>
>  A G U G A T G C C G A C G - - - - - - -   bob
>  A C G C A U A U C G C A U - - - - - - -   fred
>  C A G U A C G A U U U A U C - - - - - -   jon
>
>
>The "R 1" is static and should always appear. The "20" at the top of
>the new file should be a number defined by the user, that is they
>should be prompted for the length they wish the sequence to be. That is
>the total length of the sequence plus the added dashes could be 20 or
>3000 or whatever.  So, if they type 20 and there is only 10 letters in
>that row then the script should add 10 dashes to bring that total up to
>the 20 chosen by the user.

I'll provide one way to do this:

  # assuming $size has the number entered by the user

  while () {
my ($name) = / >(.+)/;# get the line name
chomp(my $DNA = );  # get the next line (the DNA)

# add $size - length() dashes to the end of $DNA
$DNA .= "-" x ($size - length $DNA);

# print the DNA with spaces, then a tab, then the name
print join(" ", split //, $DNA), "\t$name\n";
  }

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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




Re: formatting and syntax

2004-02-04 Thread James Edward Gray II
On Feb 4, 2004, at 11:35 AM, Michael S. Robeson II wrote:

Hi I am all still to new to PERL and I am having trouble playing with 
formatting my data into a new format. So here is my problem:

I have data (DNA sequence) in a file that looks like this:


# Infile

>bob
AGTGATGCCGACG
>fred
ACGCATATCGCAT
>jon
CAGTACGATTTATC
and I need it converted to:


# Outfile

R 1 20
 A G U G A T G C C G A C G - - - - - - -   bob
 A C G C A U A U C G C A U - - - - - - -   fred
 C A G U A C G A U U U A U C - - - - - -   jon
The "R 1" is static and should always appear. The "20" at the top of 
the new file should be a number defined by the user, that is they 
should be prompted for the length they wish the sequence to be. That 
is the total length of the sequence plus the added dashes could be 20 
or 3000 or whatever.  So, if they type 20 and there is only 10 letters 
in that row then the script should add 10 dashes to bring that total 
up to the 20 chosen by the user.

Note that there should be a space between all letters and dashes - 
including a space at the beginning. Then there are supposed to be 7 
spaces after the sequence string followed by the name as shown in the 
example output file above. Also, of note is the fact that all of the 
T's are changed to U's. For those of you that know biology I am not 
only switching formats of the data but also changing DNA to RNA.

I hope I am explaining this clear enough, but here (see below) is as 
far as I can get with the code. I just do not know how to structure 
the loop/code to do this. I always have trouble with manipulating data 
the way I want when it comes to a loop. I would prefer an easier to 
understand code rather than an efficient code. This way I can learn 
the simple stuff first and learn the short-cuts later. Thanks to 
anyone who can help.

- Cheers!
- Mike
##
#!/usr/bin/perl
use warnings;
use strict;
print "Enter the path of the INFILE to be processed:\n";

# For example "rotifer.txt" or "../Desktop/Folder/rotifer.txt"

chomp (my $infile = );

open(INFILE, $infile)
or die "Can't open INFILE for input: $!";
print "Enter in the path of the OUTFILE:\n";

# For example "rotifer_out.txt" or "../Desktop/Folder/rotifer_out.txt"

chomp (my $outfile = );

open(OUTFILE, ">$outfile")
or die "Can't open OUTFILE for input: $!";
print "Enter in the LENGTH you want the sequence to be:\n";
my ( $len ) =  =~ /(\d+)/ or die "Invalid length parameter";
print OUTFILE "R 1 $len\n\n\n\n"; # The top of the file is supposed
my $name;
while () {
	chomp;
	if (/^>(\w+)/) { $name = $1; }
	else {
		tr/T/U/;	# convert Ts to Us
		substr($_, $len) = '' if length($_) > $len;			# shorten, if needed
		$_ .= '.' x ($len - length($_)) if length($_) < $len;	# lengthen, if 
needed
		s/\b|\B/ /g;	# add spaces
		print OUTFILE "$_  $name\n";# print
	}
}

Hope that helps.

James

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



Re: formatting and syntax

2004-02-04 Thread david
Michael S. Robeson II wrote:

> I have data (DNA sequence) in a file that looks like this:
> 
> 
> # Infile
> 
>  >bob
> AGTGATGCCGACG
>  >fred
> ACGCATATCGCAT
>  >jon
> CAGTACGATTTATC
> 
> and I need it converted to:
> 
> 
> # Outfile
> 
> R 1 20
> 
>   A G U G A T G C C G A C G - - - - - - -   bob
>   A C G C A U A U C G C A U - - - - - - -   fred
>   C A G U A C G A U U U A U C - - - - - -   jon

there are many ways of doing that. here is one:

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

#--
#-- discard the first 3 header lines
#--
 for 1..3;

#--
#-- read each ' >'
#--
$/ = ' >';

while(){

next unless(my($n,$s) = /(.+)\n(.+)/);

#--
#-- pad dna sequence to 20 bytes and translate T to U
#-- here, you will prompt the user to enter a number instead
#--
($s .= '-'x(20-length($s))) =~ y/T/U/;

#--
#-- put space after each character
#--
$s =~ s/./$& /g;

print "$s\t$n\n";
}

__DATA__

# Infile

 >bob
AGTGATGCCGACG
 >fred
ACGCATATCGCAT
 >jon
CAGTACGATTTATC

__END__

prints:

A G U G A U G C C G A C G - - - - - - - bob
A C G C A U A U C G C A U - - - - - - - fred
C A G U A C G A U U U A U C - - - - - - jon

david
-- 
sub'_{print"@_ ";* \ = * __ ,\ & \}
sub'__{print"@_ ";* \ = * ___ ,\ & \}
sub'___{print"@_ ";* \ = *  ,\ & \}
sub'{print"@_,\n"}&{_+Just}(another)->(Perl)->(Hacker)

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




Re: formatting and syntax

2004-02-04 Thread Rob Dixon
Michael S. Robeson II wrote:
>
> Hi I am all still to new to PERL and I am having trouble playing with
> formatting my data into a new format. So here is my problem:
>
> I have data (DNA sequence) in a file that looks like this:
[snip]

Please don't talk about interesting stuff like DNA sequences on a Perl
group. We need less distraction.

Rob



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




Re: Formatting the decimals

2004-01-29 Thread Adam
Owen is dead on, but I think we can do that with less code. Try 
something like:

  printf ("%0.2f\n", $_) while (<>);

Regards,
Adam
On Jan 29, 2004, at 5:25 AM, Owen Cook wrote:
On Thu, 29 Jan 2004, Mallik wrote:

How do I format the decimals, i.e, if there is no
decimal part, then add .00, if there is one decimal,
then add '0'.
For eg., how to convert 123 to 123.00
and 123.5 to 123.50.
sprintf

Try this
-
#!/usr/bin/perl -w
while(){
chomp;
$formatted = sprintf ("%0.2f",$_);
print "$formatted\n";
}
__DATA__
125
123.5
2
2.3456
34.6


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



Re: Formatting the decimals

2004-01-29 Thread John W. Krahn
Mallik wrote:
> 
> Dear Friends,

Hello,

> How do I format the decimals, i.e, if there is no
> decimal part, then add .00, if there is one decimal,
> then add '0'.
> 
> For eg., how to convert 123 to 123.00
> and 123.5 to 123.50.

printf "%.2f\n", $_ for 123, 123.5;


John
-- 
use Perl;
program
fulfillment

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




Re: Formatting the decimals

2004-01-29 Thread Owen Cook

On Thu, 29 Jan 2004, Mallik wrote:

> How do I format the decimals, i.e, if there is no
> decimal part, then add .00, if there is one decimal,
> then add '0'.
> 
> For eg., how to convert 123 to 123.00
> and 123.5 to 123.50.



sprintf

Try this
-
#!/usr/bin/perl -w

while(){
chomp;
$formatted = sprintf ("%0.2f",$_);
print "$formatted\n";
}

__DATA__
125
123.5
2
2.3456
34.6



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




Re: formatting a number

2003-07-04 Thread Jenda Krynicky
From: Robert Citek <[EMAIL PROTECTED]>
> Hello all,
> 
> I want to format a number so that it has commas as a separator. 
> Here's the code I came up with:
> 
> my $num=12345678;
> print scalar reverse( join(",", grep( /./ ,split
> (/(...)/,reverse($num), "\n";
> 
> This works but was wondering if anyone might suggest a better method.
> 
> Regards,
> - Robert

use Interpolation
commify => 'commify';

print "And the result is $commify{$num}\n";

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


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



Re: formatting a number

2003-07-04 Thread Janek Schleicher
Robert Citek wrote at Thu, 03 Jul 2003 18:48:02 -0500:

> I want to format a number so that it has commas as a separator.  Here's the
> code I came up with:
> 
> my $num=12345678;
> print scalar reverse( join(",", grep( /./ ,split
> (/(...)/,reverse($num), "\n";
> 
> This works but was wondering if anyone might suggest a better method.

In addition to the FAQ, you can use the CPAN-Module Number::Format.
use Number::Format;
my $num = 12345678;
my $f = Number::Format->new(-thousands_sep => ',', -decimal_point => '.');
print $f->format_number($num),"\n";


Greetings,
Janek


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



Re: formatting a number

2003-07-03 Thread Casey West
It was Thursday, July 03, 2003 when Robert Citek took the soap box, saying:
: 
: Hello all,
: 
: I want to format a number so that it has commas as a separator.  Here's the
: code I came up with:
: 
: my $num=12345678;
: print scalar reverse( join(",", grep( /./ ,split
: (/(...)/,reverse($num), "\n";
: 
: This works but was wondering if anyone might suggest a better method.

This is something folks always want to do.  I suggest reading the FAQ
on the subject.

  perldoc -q commas added


  Casey West

-- 
If you put garbage in a computer nothing comes out but garbage. But
this garbage, having passed through a very expensive machine, is
somehow ennobled and none dare criticize it. 


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



Re: Formatting Variables.

2003-02-11 Thread Janek Schleicher
On Tue, 11 Feb 2003 08:06:33 -0600, Rgíón «hávkú wrote:

> Is there a way to give format to a Variable.

perldoc -f printf

> I mean, if I don't want to get printed 3.1415926535 (Or any irrational
> number) but something like 3.14, is there a way to use format??

perl -e 'printf "%1.2f", 3.1415926535'


Greetings,
Janek

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




RE: Formatting Variables.

2003-02-11 Thread Westgate, Jared
Ramón Chávez wrote:
> I mean, if I don't want to get printed 3.1415926535 (Or any irrational
> number) but something like 3.14, is there a way to use format??

I agree with the other posts.  Use printf.  Here is some more reading, to check out:

perldoc -q "long decimals"
perldoc -q "round"

Hope this helps,

Jared

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




RE: Formatting Variables.

2003-02-11 Thread Ramón Chávez
Thank you everyone.

sprintf is what I was looking for.

-rm-
- Original Message -
From: <[EMAIL PROTECTED]>
To: 'Ramón_Chávez' <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Tuesday, February 11, 2003 8:30 AM
Subject: RE: Formatting Variables.


> See also 'sprintf' if you don't want to print the value, but assign it:
>
> perldoc -f sprintf
> perldoc -f printf
>
> http://danconia.org
>
>
> 
> On Tue, 11 Feb 2003 09:09:55 -0500, Ken Lehman <[EMAIL PROTECTED]>
wrote:
>
> > Have you tried using printf?
> >
> > -Original Message-
> > From: Ramón Chávez [mailto:[EMAIL PROTECTED]]
> > Sent: Tuesday, February 11, 2003 9:07 AM
> > To: [EMAIL PROTECTED]
> > Subject: Formatting Variables.
> >
> >
> > Hello boys and girls.
> >
> > Is there a way to give format to a Variable.
> >
> > I mean, if I don't want to get printed 3.1415926535 (Or any irrational
> > number) but something like 3.14, is there a way to use format??
> >
> > Or I need to make some string treating (more lines)??
> >
>


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




RE: Formatting Variables.

2003-02-11 Thread wiggins
See also 'sprintf' if you don't want to print the value, but assign it:

perldoc -f sprintf
perldoc -f printf

http://danconia.org



On Tue, 11 Feb 2003 09:09:55 -0500, Ken Lehman <[EMAIL PROTECTED]> wrote:

> Have you tried using printf?
> 
> -Original Message-
> From: Ramón Chávez [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, February 11, 2003 9:07 AM
> To: [EMAIL PROTECTED]
> Subject: Formatting Variables.
> 
> 
> Hello boys and girls.
> 
> Is there a way to give format to a Variable.
> 
> I mean, if I don't want to get printed 3.1415926535 (Or any irrational
> number) but something like 3.14, is there a way to use format??
> 
> Or I need to make some string treating (more lines)??
> 

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




RE: Formatting Variables.

2003-02-11 Thread Ken Lehman
Have you tried using printf?

-Original Message-
From: Ramón Chávez [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, February 11, 2003 9:07 AM
To: [EMAIL PROTECTED]
Subject: Formatting Variables.


Hello boys and girls.

Is there a way to give format to a Variable.

I mean, if I don't want to get printed 3.1415926535 (Or any irrational
number) but something like 3.14, is there a way to use format??

Or I need to make some string treating (more lines)??

Thank you everyone.

-rm-


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



The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


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




Re: Formatting output

2002-12-26 Thread R. Joseph Newton
Hi,

I'm going to take this from here, rather than go on to the full code, because I think 
I see the core of the problem here.  The foreach just isn't going to do it for what 
you want, although you maight call it on one of the hashes.  You don't really indicate 
whether there is supposed to be any meaningful parallelism across columns, and on that 
factor rests the distinction in strategy.

If the columns do have some one-to-one relationship between lines, you would want to 
foreach one of the hashes, then reference the corresponding element of the other.  If 
there is no relationship across columns, then you have three jobs to do:
1) Get %TARGET into an array of preformatted strings, keeping count of the number of 
strings produced.
1) Get %PROD into an array of preformatted strings, keeping count of the number of 
strings produced.
2) For the legth of the shorter array, output an element from one array then the other 
on each line.
3) For the remaining length of the longer array format your output to compensate for 
the missing column.
You note that I specified three jobs, but you see four items above.  The first two 
should work very well with a properly parameterized sub.

Jensen Kenneth B SrA AFPC/DPDMPQ wrote:

> Accidentally sent before I was done writing.
>
> I am trying to iterate through two hashes and print each key/value. In one
> column the key/value from one hash and another column the key/values of the
> other hash. So the output would look something like this
>
> Some header   |header for column 2
> Key value key value
> Key value key value
> Key value key value
> Key value key value
> Key value key value
> Key value key value
> Key value
> Key value
>
> Etc...
>
> Here's what I am doing right now
>
> ($a, $b, $c) = 0;
>   foreach (sort keys (%TARGET)){
> @TEMP[$a] = "$_ $TARGET{$_}";
> $a++;
>   }
>   foreach (sort keys (%PROD)){
> @TEMP2[$b] = "$_ $PROD{$_}";
> $b++;
>   }
>   print OUT "\@ prod not present.|Present not at prod.\n";
>   if ($a > $b){
> for ($n=0 , $n = $a, $n++){
>   printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]);
> }
>   } else {
> for ($n=0 , $n = $b, $n++){
>   printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]);
> }
>   }


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




RE: Formatting output

2002-12-26 Thread Bob Showalter
> -Original Message-
> From: Jensen Kenneth B SrA AFPC/DPDMPQ
> [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 26, 2002 9:46 AM
> To: '[EMAIL PROTECTED]'
> Subject: Formatting output
> 
> 
> Accidentally sent before I was done writing.
> 
> I am trying to iterate through two hashes and print each 
> key/value. In one
> column the key/value from one hash and another column the 
> key/values of the
> other hash. So the output would look something like this
> 
> Some header   |header for column 2
> Key value key value
> Key value key value
> Key value key value
> Key value key value
> Key value key value
> Key value key value
> Key value
> Key value
> 
> Etc...
> 
> Here's what I am doing right now
> 
> ($a, $b, $c) = 0;
>   foreach (sort keys (%TARGET)){
> @TEMP[$a] = "$_ $TARGET{$_}";
> $a++;
>   }
>   foreach (sort keys (%PROD)){
> @TEMP2[$b] = "$_ $PROD{$_}";
> $b++;
>   }
>   print OUT "\@ prod not present.|Present not at prod.\n"; 
>   if ($a > $b){
> for ($n=0 , $n = $a, $n++){
>   printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]);
> }
>   } else {
> for ($n=0 , $n = $b, $n++){
>   printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]);
> }
>   }
> 

Perl's real good at iterating. You might try something like this:

   my (@TEMP, @TEMP2);
   push @TEMP, "$_ $TARGET{$_}" for sort keys %TARGET;
   push @TEMP2, "$_ $PROD{$_}" for sort keys %PROD;
   printf OUT "%-15.15s   %-15.15s\n", shift @TEMP, shift @TEMP2 
   while @TEMP || @TEMP2;

That last line will throw some warnings about undefined values if you're
using -w. You can suppress those with (Perl 5.6 or higher):

   {
   no warnings 'undefined';
   printf OUT "%-15.15s   %-15.15s\n", shift @TEMP, shift @TEMP2 
   while @TEMP || @TEMP2;
   }

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




RE: Formatting output

2002-12-26 Thread Jensen Kenneth B SrA AFPC/DPDMPQ
Wasn't really clear what I was trying to accomplish. Basically I am trying
to iterate through 2 hashes at the same time so I can print 1 key / value
pair from each hash on the same line. Repeating through each hash. Making
things more complicated I am forced to use perl4 with no libraries, so I
can't use any of the nifty modules from cpan etc. I've tried to get the
sysad's here to upgrade, but it seems it will take an act of congress to get
them to upgrade these archaic systems. Here's the whole script and some
output that is produced, truncated (full file is about 3000 lines). Script
takes reports from our repository with file names and the current version
that is supposed to be fielded, and a report with the filenames and version
of what is actually on the live server. Validating the server.

#!/usr/contrib/bin/perl

$CPROD, $CTARGET, $CVALID, $CINVAL = 0;
open (PROD, "@ARGV[0]");
  %PROD = ("file", "version");
  while (){
unless (grep(/^Change|^\n/,$_)){
  ($FILE, $VER) = ($_ =~ m/(\S+)\s+\S+\s+\S+\s+\S+\s+(\S+)/);
  ($FILE = substr($FILE,rindex($FILE,"\\")+1)) =~ y/A-Z/a-z/;
  $PROD{$FILE} = $VER;
}
$CPROD++;
   }
close PROD;

open (TARGET, "@ARGV[1]");
  %TARGET = ("file", "version");
  %PKG = ("file", "package");
  while (){
unless (grep(/^NAME|^\-|^\s|selected\.$|^Input|^\n/,$_)){
  ($PACKAGE, $FILE, $VER) = ($_ =~ m/(\S+)\s+(\S+)\s+(\S+)/);
  ($FILE = substr($FILE,rindex($FILE,"\/")+1)) =~ y/A-Z/a-z/;
  $TARGET{$FILE} = $VER;
  $PKG{$FILE} = $PACKAGE;
  $CTARGET++;
}
  }
close TARGET;

#if (@ARGV[2]){
#  open (VIEWS, "@ARGV[2]");
#%VIEWS = ("file", "version");
#while (){
#  if (grep(/^\/\*/,$_)){
#unless (grep(/^\/\*\+/,$_)){
#  ($_ = substr($_,(index($_,"L" =~ s/\s+$/\n/;
#  ($FILE, $VER) = ($_ =~ m/(\S+)\s+(\S+)/);
#  ($FILE = substr($FILE,rindex($FILE,"\/")+1)) =~ y/A-Z/a-z/;
#  $PROD{$FILE} = $VER;
#}
#  }
#}
#  close VIEWS;
#}

open (OUT, ">valid.out");
  foreach (sort keys (%PROD)){
unless ($_ eq "file"){
  $FILE = $_;
  $VER = $PROD{$_};
#  print OUT "Checking for $FILE version $VER\n"; 
  foreach (sort keys (%TARGET)){
if ($_ eq $FILE){
  if ($VER eq $TARGET{$_}){
unless ($_ eq "file"){
#  print OUT "File $_ is present & the correct version.
$TARGET{$_}\n\n";
  $CVALID++;
}
delete $TARGET{$_};
delete $PROD{$FILE};
  } else {
print OUT "!File $_ is present but not correct version!
Production version is $VER, version present is $TARGET{$_}.\n\n";
$CINVAL++;
delete $TARGET{$_};
delete $PROD{$FILE};
  }
}
  }
#  foreach (sort keys (%VIEWS)){

#  }
}
  }
  ($a, $b, $c) = 0; 
  foreach (sort keys (%TARGET)){
@TEMP[$a] = "$_ $TARGET{$_}";
$a++;
  }
  foreach (sort keys (%PROD)){
@TEMP2[$b] = "$_ $PROD{$_}";
$b++;
  }
  print OUT "\@ prod not present.|Present not at prod.\n"; 
  if ($a > $b){
for ($n=0 , $n = $a, $n++){
  printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]);
}
  } else {
for ($n=0 , $n = $b, $n++){
  printf OUT "%15s %15s\n", (@TEMP[$n], @TEMP2[$n]);
}
  }
  print OUT "Production Files   Files PresentFiles ValidFiles
Invalid\n"; 
  printf OUT " %-5d %-5d   %-5d  %-5d",
($CPROD, $CTARGET, $CVALID, $CINVAL);
close OUT;


Output file 

~~

!File syoffevs.svl is present but not correct version! Production version is
8.0, version present is 8.1.

!File syprb.svl is present but not correct version! Production version is
8.0, version present is 9.0.

!File syprs.svl is present but not correct version! Production version is
8.0, version present is 9.0.

!File uq124b.svl is present but not correct version! Production version is
1.1, version present is 1.3.

!File uq291b.svl is present but not correct version! Production version is
9.0, version present is 7.1.

!File uq291s.svl is present but not correct version! Production version is
9.0, version present is 7.1.

!File uqafpacb.svl is present but not correct version! Production version is
1.5, version present is 1.3.

!File uqafpacs.svl is present but not correct version! Production version is
1.1, version present is 1.0.

!File uqpulxb.svl is present but not correct version! Production version is
7.3, version present is 6.3.

!File uqpulxs.svl is present but not correct version! Production version is
7.3, version present is 6.3.

@ prod not present.|Present not at prod.
   
   
   
Production Files   Files PresentFiles ValidFiles Invalid
 1422  1310 1129 28   

~~

RE: formatting output

2002-12-12 Thread Mystik Gotan
And sprintf(), format().



--
Bob Erinkveld (Webmaster Insane Hosts)
www.insane-hosts.net
MSN: [EMAIL PROTECTED]






From: "Paul Kraus" <[EMAIL PROTECTED]>
To: "'Mariusz'" <[EMAIL PROTECTED]>,	"'perl'" <[EMAIL PROTECTED]>
Subject: RE: formatting output
Date: Thu, 12 Dec 2002 07:59:54 -0500

Also look up function printf.

> -Original Message-
> From: Mariusz [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, December 12, 2002 12:46 AM
> To: perl
> Subject: formatting output
>
>
> I'm outputting lots of text into an email message. I would
> like to have some basic control over the way how it is
> presented, but the only command I know is "\n" - new line.
> What about tab, spaces, etc..?
>
> Mariusz
>


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



_
MSN Zoeken, voor duidelijke zoekresultaten! 
http://search.msn.nl/worldwide.asp


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



RE: formatting output

2002-12-12 Thread Paul Kraus
Also look up function printf.

> -Original Message-
> From: Mariusz [mailto:[EMAIL PROTECTED]] 
> Sent: Thursday, December 12, 2002 12:46 AM
> To: perl
> Subject: formatting output
> 
> 
> I'm outputting lots of text into an email message. I would 
> like to have some basic control over the way how it is 
> presented, but the only command I know is "\n" - new line. 
> What about tab, spaces, etc..?
> 
> Mariusz
> 


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




Re: formatting output

2002-12-11 Thread Narayan Kumar

Hope this is what you need

\r -> return;
\t -> tab
\f -> form feed
\b -> backspace
\a -> bell
\e -> escape
\007 -> Any octal ASCII value ( here, 007 = bell )
\x7f -> Any hex ASCII value   ( here, 7f = delete )
..
...


>From the 
Llama Book 
pg: 24

Narayan

On Wed, 11 Dec 2002, Mariusz wrote:

|I'm outputting lots of text into an email message. I would like to have some basic 
|control over the way how it is presented, but the only command I know is "\n" - new 
|line. What about tab, spaces, etc..?
|
|Mariusz
|


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




Re: formatting output

2002-12-11 Thread bansidhar

tab is \t and space is normal space

*** REPLY SEPARATOR  ***

On 12/11/02 at 11:45 PM Mariusz wrote:

>I'm outputting lots of text into an email message. I would like to have
>some basic control over the way how it is presented, but the only command
>I know is "\n" - new line. What about tab, spaces, etc..?
>
>Mariusz




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




RE: Formatting date, time

2002-08-13 Thread Bob Showalter

> -Original Message-
> From: Bob Showalter [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 13, 2002 9:33 AM
> To: 'Gregg O'Donnell'; [EMAIL PROTECTED]
> Subject: RE: Formatting date, time
> 
> ...
> or, 2) Use the POSIX module's strftime(), which is simpler:
> 
>use POSIX 'strftime';
>my $date = strftime('%02m%02d%02y%02H%02M', localtime);

Oops! Leave off the '02' parts:
 
my $date = strftime('%m%d%y%H%M', localtime);

Sorry about that

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




RE: Formatting date, time

2002-08-13 Thread Bob Showalter

> -Original Message-
> From: Gregg O'Donnell [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, August 13, 2002 9:14 AM
> To: [EMAIL PROTECTED]
> Subject: Formatting date, time
> 
> I'm looking for the simplest way to use the date and time in 
> the format of MMDDYYHHmm (no spaces), which is used later in 
> the program.

Use the POSIX module's strftime() (see below)

> 
> Here's what I've come up with; comments or suggestions are 
> appreciated.
> 
> #Insert Date and Time
> my $month = $mon00   #Two digit month
> my $day = $mday00   #Two digit day in month
> my $year = $year#Two digit year
> my $hour = $hour00   #Two digit: Hour
> my $min = $min00   #Two digit: Minutes

Why are you assigning one set of variables to another
set of variables? Also, these statements lack semicolons.
Where did the values in $mon00, $mday00, etc. come from?

> #Combine date and time above into MMDDYYHHmm format
> my @log_date = qw($month$day$year$hour$min)

Nope, that's not what qw// is for. See perldoc perlop
for more details.

To answer the original question:

1) Use localtime() and sprintf(), which is a bit messy:

   my (undef,$min,$hour,$mday,$mon,$year) = localtime;
   my $date = sprintf '%02d%02d%02d%02d%02d', $m + 1, $d,
   $y % 100, $hour, $min;

or, 2) Use the POSIX module's strftime(), which is simpler:

   use POSIX 'strftime';
   my $date = strftime('%02m%02d%02y%02H%02M', localtime);

perldoc -f localtime
perldoc -f sprintf
perldoc POSIX

HTH

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




Re: Formatting date, time

2002-08-13 Thread Robin Norwood

"Gregg O'Donnell" <[EMAIL PROTECTED]> writes:

>  
> 
> I'm looking for the simplest way to use the date and time in the format of 
>MMDDYYHHmm (no spaces), which is used later in the program.
> 
> Here's what I've come up with; comments or suggestions are appreciated.
> 
> #Insert Date and Time
> my $month = $mon00   #Two digit month
> my $day = $mday00   #Two digit day in month
> my $year = $year#Two digit year
> my $hour = $hour00   #Two digit: Hour
> my $min = $min00   #Two digit: Minutes
> #Combine date and time above into MMDDYYHHmm format
> my @log_date = qw($month$day$year$hour$min)

That depends on what format you start with...
Short version:

'
#!/usr/bin/perl -wl

use strict;

use POSIX;

my @time = localtime(time);

print POSIX::strftime("%m%d%y%H%M",@time);
'

time is 'unixtime'.  localtime in array context returns a 'time
array', whose format you can read about in the docs.

strftime uses an ansi c standard time format string - there are
several places you can look up the possible arguments.

-RN

-- 

Robin Norwood
Red Hat, Inc.

"The Sage does nothing, yet nothing remains undone."
-Lao Tzu, Te Tao Ching

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




Re: Formatting date, time

2002-08-13 Thread Tor Hildrum

<[EMAIL PROTECTED]> wrote:
> #Insert Date and Time
> my $month = $mon00   #Two digit month
> my $day = $mday00   #Two digit day in month
> my $year = $year#Two digit year
??
> my $hour = $hour00   #Two digit: Hour
> my $min = $min00   #Two digit: Minutes
> #Combine date and time above into MMDDYYHHmm format
> my @log_date = qw($month$day$year$hour$min)

Do you want interpolation here?
[localhost:~] tor% perl -e '$var=12; $var2=24; @r=qw($var$var2); print
"@r\n";'
$var$var2
[localhost:~] tor% 

my $date = $mon00.$mday00.$year.$hour00.$min00;

Tor


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




Re: Formatting

2002-06-21 Thread John W. Krahn

"Shishir K. Singh" wrote:
> 
> Thanks to Mark, John, David and Timothy!! I get the results if I use the 
>combination of
> 
> eg $myVar = 'ABCDEFGHIJKLMNOP';
> $newVar = pack('A10',$myVar);
> $newVar should have 'ABCDEFGHIJ'; # Works and faster than sprintf
> 
> eg $myVar = 'ABCD';
> $newVar = pack('A10',$myVar);
> $newVar should have 'ABCD  '; # Works and faster than sprintf
> 
> eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
> $newVar = sprintf("%-10.10s, $myVar);
> $newVar should have '  ABCD'; # Works. Have to use sprintf as nothing available 
>for right justify in pack.
> 
> Think pack is an elegant way of truncating a string.

That is what substr() was created for.  :-)

my $myVar = 'ABCDEFGHIJKLMNOP';

print substr( $myVar, 0, 10 ); # prints ABCDEFGHIJ
print substr( $myVar, -10 );   # prints GHIJKLMNOP


John
-- 
use Perl;
program
fulfillment

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




RE: Formatting

2002-06-21 Thread Shishir K. Singh

> 
> Hi,

Hello,

> I need to format a string in a fixed width field. The string
> may be less than the length of the format, or may be greater.
> If less, then it should get  padded with spaces (left or right
> justified , like using - in sprintf), if greater, then the
> string should get truncated to the exact length.
> 
> eg $myVar = 'ABCDEFGHIJKLMNOP';
> $newVar = sprintf("%10s,$myVar);
> $newVar should have 'ABCDEFGHIJ'; # But has the full length i.e. 'ABCDEFGHIJKLMNOP'
> 
> eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
> $newVar = sprintf("%10s,$myVar);
> $newVar should have '  ABCD'; # Works
> 
> eg $myVar = 'ABCD'; (Left Aligned, padded with spaces)
> $newVar = sprintf("%-10s,$myVar);
> $newVar should have 'ABCD  '; # Works
> 
> I am not able to lay my finger on the correct format to achieve
> 1st and the 2nd with the same format. Am I missing something ,
> or is there another way out? Any help would be greatly appreciated.



>Fun with sprintf.  :-)

>$ perl -le'
>for $word ( qw/ABCDEFGHIJKLMNOP ABCD/ ) {
>$string = sprintf q/%10.10s  %-10.10s  %10s  %-10s/, ($word) x 4;
>print $string; 
>$string = sprintf q/%*.*s  %-*.*s  %*s  %-*s/, (10,10,$word) x 2, (10,$word) x 2;
>print $string;
>}
>'
>ABCDEFGHIJ  ABCDEFGHIJ  ABCDEFGHIJKLMNOP  ABCDEFGHIJKLMNOP
>ABCDEFGHIJ  ABCDEFGHIJ  ABCDEFGHIJKLMNOP  ABCDEFGHIJKLMNOP
>  ABCD  ABCD  ABCD  ABCD  
>  ABCD  ABCD  ABCD  ABCD  


Thanks to Mark, John, David and Timothy!! I get the results if I use the 
combination of 

eg $myVar = 'ABCDEFGHIJKLMNOP';
$newVar = pack('A10',$myVar);
$newVar should have 'ABCDEFGHIJ'; # Works and faster than sprintf

eg $myVar = 'ABCD';
$newVar = pack('A10',$myVar);
$newVar should have 'ABCD  '; # Works and faster than sprintf
 
eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
$newVar = sprintf("%-10.10s, $myVar);
$newVar should have '  ABCD'; # Works. Have to use sprintf as nothing available 
for right justify in pack.


Think pack is an elegant way of truncating a string.

Thanks
Shishir 




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




Re: Formatting

2002-06-21 Thread John W. Krahn

"Shishir K. Singh" wrote:
> 
> Hi,

Hello,

> I need to format a string in a fixed width field. The string
> may be less than the length of the format, or may be greater.
> If less, then it should get  padded with spaces (left or right
> justified , like using - in sprintf), if greater, then the
> string should get truncated to the exact length.
> 
> eg $myVar = 'ABCDEFGHIJKLMNOP';
> $newVar = sprintf("%10s,$myVar);
> $newVar should have 'ABCDEFGHIJ'; # But has the full length i.e. 'ABCDEFGHIJKLMNOP'
> 
> eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
> $newVar = sprintf("%10s,$myVar);
> $newVar should have '  ABCD'; # Works
> 
> eg $myVar = 'ABCD'; (Left Aligned, padded with spaces)
> $newVar = sprintf("%-10s,$myVar);
> $newVar should have 'ABCD  '; # Works
> 
> I am not able to lay my finger on the correct format to achieve
> 1st and the 2nd with the same format. Am I missing something ,
> or is there another way out? Any help would be greatly appreciated.



Fun with sprintf.  :-)

$ perl -le'
for $word ( qw/ABCDEFGHIJKLMNOP ABCD/ ) {
$string = sprintf q/%10.10s  %-10.10s  %10s  %-10s/, ($word) x 4;
print $string; 
$string = sprintf q/%*.*s  %-*.*s  %*s  %-*s/, (10,10,$word) x 2, (10,$word) x 2;
print $string;
}
'
ABCDEFGHIJ  ABCDEFGHIJ  ABCDEFGHIJKLMNOP  ABCDEFGHIJKLMNOP
ABCDEFGHIJ  ABCDEFGHIJ  ABCDEFGHIJKLMNOP  ABCDEFGHIJKLMNOP
  ABCD  ABCD  ABCD  ABCD  
  ABCD  ABCD  ABCD  ABCD  



John
-- 
use Perl;
program
fulfillment

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




Re: Formatting

2002-06-20 Thread Marco Antonio Valenzuela Escárcega

On Thu, 2002-06-20 at 22:42, Shishir K. Singh wrote:
> Hi, 
hi
> 
> I need to format a string in a fixed width field. The string may be less than the 
>length of the format, or may be greater. If less, then it should get  padded with 
>spaces (left or right justified , like using - in sprintf), if greater, then the 
>string should get truncated to the exact length. 
> 
> 
> eg $myVar = 'ABCDEFGHIJKLMNOP';
> $newVar = sprintf("%10s,$myVar);
> $newVar should have 'ABCDEFGHIJ'; # But has the full length i.e. 'ABCDEFGHIJKLMNOP'
> 
> eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
> $newVar = sprintf("%10s,$myVar);
> $newVar should have '  ABCD'; # Works
> 
> eg $myVar = 'ABCD'; (Left Aligned, padded with spaces)
> $newVar = sprintf("%-10s,$myVar);
> $newVar should have 'ABCD  '; # Works
> 
> 
> I am not able to lay my finger on the correct format to achieve 1st and the 2nd with 
>the same format. Am I missing something , or is there another way out? Any help would 
>be greatly appreciated.
> 
you can try using pack:

$myVar = 'ABCDEFGHIJKLMNOP';
$newVar = pack 'A10', $myVar;
$newVar eq 'ABCDEFGHIJ';

$myVar = 'ABCD';
$newVar = pack 'A10', $myVar;
$newVar eq 'ABCD  ';



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




RE: Formatting

2002-06-20 Thread Timothy Johnson

 
Try testing for the length of the string and then using the substr()
function to get the part that you want for strings that are longer than
desired.

-Original Message-
From: Shishir K. Singh
To: [EMAIL PROTECTED]
Sent: 6/20/02 10:42 PM
Subject: Formatting

Hi, 

I need to format a string in a fixed width field. The string may be less
than the length of the format, or may be greater. If less, then it
should get  padded with spaces (left or right justified , like using -
in sprintf), if greater, then the string should get truncated to the
exact length. 


eg $myVar = 'ABCDEFGHIJKLMNOP';
$newVar = sprintf("%10s,$myVar);
$newVar should have 'ABCDEFGHIJ'; # But has the full length i.e.
'ABCDEFGHIJKLMNOP'

eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
$newVar = sprintf("%10s,$myVar);
$newVar should have '  ABCD'; # Works

eg $myVar = 'ABCD'; (Left Aligned, padded with spaces)
$newVar = sprintf("%-10s,$myVar);
$newVar should have 'ABCD  '; # Works


I am not able to lay my finger on the correct format to achieve 1st and
the 2nd with the same format. Am I missing something , or is there
another way out? Any help would be greatly appreciated.

Thanks
Shishir

 

-- 
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: Formatting

2002-06-20 Thread David . Wagner

You can build the format string:

my $myVar = 'ABCD'; #(Left Aligned, padded with spaces)
#$newVar = sprintf("%-10s,$myVar);
#$newVar should have 'ABCD  '; # Works

while ( 1 ) {
   printf "eft or ight: ";
   chomp(my $MyInput = );
   last if ( $MyInput =~ /^ex/i );
   my $MySign = '-';
   $MySign = '' if ( $MyInput =~ /^r/i );
   my $MyFormat = '%' . $MySign . '10s';
   printf "${MyFormat}\n", $myVar;
 }

Depending on whether left or right, it will print out as such. Could do this
with sprintf also.

Wags ;)

-Original Message-
From: Shishir K. Singh [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 20, 2002 22:42
To: [EMAIL PROTECTED]
Subject: Formatting


Hi, 

I need to format a string in a fixed width field. The string may be less
than the length of the format, or may be greater. If less, then it should
get  padded with spaces (left or right justified , like using - in sprintf),
if greater, then the string should get truncated to the exact length. 


eg $myVar = 'ABCDEFGHIJKLMNOP';
$newVar = sprintf("%10s,$myVar);
$newVar should have 'ABCDEFGHIJ'; # But has the full length i.e.
'ABCDEFGHIJKLMNOP'

eg $myVar = 'ABCD'; (Right Aligned, padded with spaces)
$newVar = sprintf("%10s,$myVar);
$newVar should have '  ABCD'; # Works

eg $myVar = 'ABCD'; (Left Aligned, padded with spaces)
$newVar = sprintf("%-10s,$myVar);
$newVar should have 'ABCD  '; # Works


I am not able to lay my finger on the correct format to achieve 1st and the
2nd with the same format. Am I missing something , or is there another way
out? Any help would be greatly appreciated.

Thanks
Shishir

 

-- 
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: Formatting output

2002-06-13 Thread John W. Krahn

Frank Newland wrote:
> 
> I want to format the output of my database query.
> 
> Current code
> while (@row =$sth->fetchrow() ) {
>  print  join(',',@row);
>  }
> 
> Results
> 1.38, .0396,.0076
> 
> Desired Results
> 1.38, 0.0396, 0.0076


$ perl -le'print join ", ", map { sprintf "%.4f", $_ } ( 1.38, .0396, .0076 )'
1.3800, 0.0396, 0.0076


John
-- 
use Perl;
program
fulfillment

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




Re: Formatting output

2002-06-13 Thread Jeff 'japhy' Pinyan

On Jun 13, Frank Newland said:

>Results
>1.38, .0396,.0076
>
>Desired Results
>1.38, 0.0396, 0.0076
>
>$row[0] = sprintf("%04d",$row[2]);  ## results in  ==> 0.
>$row[1] = sprintf("%0d.%04d",$row[4]);  ## results in ==>0.

%d is for INTEGERS.  You have floating points, so use %f.

-- 
Jeff "japhy" Pinyan  [EMAIL PROTECTED]  http://www.pobox.com/~japhy/
RPI Acacia brother #734   http://www.perlmonks.org/   http://www.cpan.org/
** Look for "Regular Expressions in Perl" published by Manning, in 2002 **
 what does y/// stand for?   why, yansliterate of course.
[  I'm looking for programming work.  If you like my work, let me know.  ]


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




Re: Formatting output

2002-06-13 Thread Ovid

> I want to format the output of my database query.
> Current code 
> while (@row =$sth->fetchrow() ) {
>  print  join(',',@row);
>  }
> 
> Results
> 1.38, .0396,.0076
> 
> Desired Results
> 1.38, 0.0396, 0.0076

Frank,

It's tough for me to be sure exactly what you are wanting for formatting, so I would 
recommend
reading

perldoc -f sprintf

In the meantime, this will get what you have asked for:

my @nums = qw/ 1.38 .0396 .0076 /;
printf("%.2f, %.4f, %.4f", @nums);

Cheers,
Curtis "Ovid" Poe

=
"Ovid" on http://www.perlmonks.org/
Someone asked me how to count to 10 in Perl:
push@A,$_ for reverse q.e...q.n.;for(@A){$_=unpack(q|c|,$_);@a=split//;
shift@a;shift@a if $a[$[]eq$[;$_=join q||,@a};print $_,$/for reverse @A

__
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

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




Re: Formatting in perl

2002-06-09 Thread drieux


On Friday, June 7, 2002, at 11:03 , Danial Magid wrote:
[..]
>
> I am trying to put together a process that will format and print out
> checks (pay stbus), so I need to do a bit of formatting and combine the
> right fonts.
>
> I was wondering if there are any books or urls I could use for reference.

as david mentioned - this tends to be stuff at the
printer layer - in terms of font selection -
but you can get basic types of 'formatting'
sorted out with things like

perldoc perlform

At which point you will probably either be working the process of
say

open(derPrinter, "$printer $printArgs|")
or die "not able to popen printer:$!\n";

# do the select foo for derPrinter for the
# stuff you want to ship there.

close(derPrinter);

you may want to look at the available 'graphics' libraries:

http://search.cpan.org/Catalog/Graphics/

the GD family is hot - although the kult of Image::Magick
has it's defenders... since if you can get to a basic 'image'
then you can normally push that out to most post modern printers.

Assuming that your target printer is a network printer that
allows TFTP then you might want to scope out:

http://search.cpan.org/doc/GSM/TFTP-1.0b3/README

or

http://search.cpan.org/search?module=Net::TFTP

{ now it may be a reach to send you to say
http://search.cpan.org/search?dist=LEGO-RCX -
to have the lego robot go over and change settings... }

so there are a whole bunches of routes to a solution
that you could try - we'd need to know a few things more
about which OS to what printer by which interfaces




ciao
drieux

---


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




Re: Formatting in perl

2002-06-07 Thread David T-G

Danial --

...and then Danial Magid said...
% 
% Hi,

Hello!


% 
% I am trying to put together a process that will format and print out
% checks (pay stbus), so I need to do a bit of formatting and combine the
% right fonts.

Who needs fonts?  COURIER RUL3Z AND ASC11 IS DA B0MB, D00D! ;-)


% 
% I was wondering if there are any books or urls I could use for reference.

Do you know perl already or are you starting out?

perl itself doesn't know from fonts or any other printer-specific
configuration, though there's no reason it couldn't spit out the right
stuff on demand once you told it how to do so.  It will handle formatting
well and is a natural for accessing your database of employees and
processing what comes back out.

Rather than mess with funky escape codes for picking fonts and the like,
you might consider having perl output TeX source (hey, there might be a
module) so that you can then process *that* and do the pretty part.

An excellent reference is "The Camel Book", O'Reilly's Programming
Perl.  It doesn't quite take you by the hand, but it's still quite
understandable.


% 
% Thanks,
%Danial


HTH & HAND

:-D
-- 
David T-G  * It's easier to fight for one's principles
(play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie
(work) [EMAIL PROTECTED]
http://www.justpickone.org/davidtg/Shpx gur Pbzzhavpngvbaf Qrprapl Npg!




msg25632/pgp0.pgp
Description: PGP signature


RE: Formatting String output

2002-05-29 Thread Bob Showalter

> -Original Message-
> From: Heiko Heggen [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 29, 2002 5:48 AM
> To: [EMAIL PROTECTED]
> Subject: Formatting String output
> 
> 
> Hi Guys.
> 
> I want to format my String output with the 'printf' command, 
> but I cant find
> the solution. For you experienced people this is not problem 
> I think, so
> could you give me the right hint, please
> 
> What I want to do:
> I have several arrays which contains a certain number of strings with
> different length. And I want to generate an output like this:
> 
> asdfg  a  as asdf
> as asdf   asdfgh a
> asdf   asdfg  a  asdfgh
> 
> I think this is something like that:
> for ($i=0; $i<$arrayCount; $i++)
> { printf("%s", myArray[$i]:10); }
> 
> But this does not work. Where is the fault.

All the details are in:

   perldoc -f sprintf

To output in a field of 10 cols:

   printf('%10s', 'Hello'); 
   # prints ' Hello'

Default is right-justified. To left-justify:

   printf('%-10s', 'Hello'); 
   # prints 'Hello '

Default is to expand the field if input is longer. To
truncate to exactly 10 chars (and left-justify):

   printf('%-10.10s', 'ARatherLongString'); 
   # prints 'ARatherLon'

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




Re: Formatting Output

2002-05-29 Thread Janek Schleicher

Melissa Cama wrote at Wed, 29 May 2002 03:13:46 +0200:

> ...
> I need to print out each value in the array (for each key) as a new line in an 
>excel/CSV file.
> Also with each new line, a time stamp needs to be printed.

> ...
>   foreach $str_feature (%hash_FeatureUsers){
  ^^^
 foreach $str_feature (keys %hash_FeatureUsers) {
>   
>   foreach my $val (@{$hash_FeatureUsers{$str_feature}}) {

Or if you're really only interested in your values:
foreach my $val_ref (values %hash_FeatureUsers) {
my $val = @$val_ref
...

>   print (userfile 
>$STR_CVSSTRINGBRACKET.&GetTimeStamp().$STR_CVSSTRINGBRACKET); print
>   (userfile $STR_CVSCOMMA."$val\n");
>   }
>   }
>   }
>   }   

Greetings,
Janek

PS:
> This message and
> any attachment is confidential and may be privileged or otherwise protected from 
>disclosure.  If
> you have received it by mistake please let us know by reply and then delete it from 
>your system;
> you should not copy the message or disclose its contents to anyone.
 
I have to inform you, that this message arrived many not confidential people.
I have to inform you, that the message was copied by many servers and
can be read with google or so in some hours.

I didn't delete, will I be arrested or is there a chance for me ?!

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




Re: Formatting Output

2002-05-28 Thread John W. Krahn

Melissa Cama wrote:
> 
> Hi,

Hello,

> I currently have a hash which has one value as the key, and then
> an array of values assigned to this key.  However the arrays are
> different lengths.
> 
> I need to print out each value in the array (for each key) as a
> new line in an excel/CSV file.  Also with each new line, a time
> stamp needs to be printed.
> 
> For example this is the format i need. - I dont need the keys(features)
> to be printed out just the values in the array assigned to this key.
> 
> Feature1Feature2
> timestamp   value 1 of array1   value 1 of array2
> timestamp   value 2 of array1   value 2 of array2
> timestamp   value 3 of array2
> 
> This is my code just for the printing:
> 
> foreach $str_feature (%hash_FeatureUsers){
> foreach my $val (@{$hash_FeatureUsers{$str_feature}}) {
> print (userfile $STR_CVSSTRINGBRACKET.&GetTimeStamp().$STR_CVSSTRINGBRACKET);
> print (userfile $STR_CVSCOMMA."$val\n");
> }
> }
> 
> At the moment this is only printing the values of one array, and
> it does it three times.
> 
> Any help would be appreciated.  I know its quite difficult to
> understand, my explanation isn't very good.


Something like this should work:

for my $str_feature ( keys %hash_FeatureUsers ) {
print userfile $STR_CVSSTRINGBRACKET .
   GetTimeStamp() .
   $STR_CVSSTRINGBRACKET .
   $STR_CVSCOMMA .
   join( $STR_CVSCOMMA,
@{$hash_FeatureUsers{$str_feature}} ) .
   "\n";
}



John
-- 
use Perl;
program
fulfillment

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




Re: formatting numbers

2002-04-29 Thread John W. Krahn

Pat wrote:
> 
> I have been through man printf, info printf and perldoc -f print and still
> can't find how to format numbers.
> In the program below I would like to print the numbers as below:
> 383.3as 383.30

$ perl -le'printf "%.2f\n", 383.3'
383.30

> 37492908 as 37 492 908

If we slightly modify the commify() sub from perlfaq5

$ perl -e'
sub commify {
local $_  = shift;
1 while s/^([-+]?\d+)(\d{3})/$1 $2/;
return $_;
}
print commify( 37492908 ), "\n"'
37 492 908

> 35.7560234069824 as 35.76

$ perl -le'printf "%.2f\n", 35.7560234069824'
35.76

> 1631.11929000261 as 1 631

$ perl -e'
sub commify {
local $_  = shift;
1 while s/^([-+]?\d+)(\d{3})/$1 $2/;
return $_;
}
print commify( int( 1631.11929000261 ) ), "\n"'
1 631


John
-- 
use Perl;
program
fulfillment

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




RE: formatting numbers

2002-04-28 Thread Timothy Johnson

 
I can't test these, but I think they will work.  Play around with sprintf a
little bit.  Don't forget to check out 'perldoc -f sprintf'.

383.3as 383.30 
   $var = sprintf("%3.2f",$var)

37492908 as 37 492 908 
   if($var 1 =~ /(\d{2})(\d{3})(\d{3})/){
  $formattedvar = "$1 $2 $3";
   }else{
  print "data formatted incorrectly!\n";
   }

35.7560234069824 as 35.76
   $var = sprintf("%2.2f",$var);

1631.11929000261 as 1 631
   $intvar = int($var); #strip off the trailing decimal number
   $intvar =~ /(\d)(\d{3})/;#match for one digit followed by three
   $formattedvar = "$1 $2";#new var = result from first parentheses
   #followed by a space and the second

-Original Message-
From: pat
To: [EMAIL PROTECTED]
Sent: 4/28/02 7:03 AM
Subject: formatting numbers

I have been through man printf, info printf and perldoc -f print and
still
can't find how to format numbers.
In the program below I would like to print the numbers as below:
383.3as 383.30
37492908 as 37 492 908
35.7560234069824 as 35.76
1631.11929000261 as 1 631
Please can someone put me right. Many thanks for introducing me to the
split
command/function it sure is a winner.
My simple program which prints unformatted is below
Many thanks Pat.
Program follows:-
#!/usr/bin/perl
#Program that needs formatting of numbers
$Tot_time="383.3";
$Grand_total="37492908";
$Tot_megsG = $Grand_total / 1024 /1024;
print "Grand Total   = $Grand_total\t";
print "$Tot_megsG  megabytes\n\n";
print "Total time= $Tot_time in minutes \n\n";
$seconds = ($Tot_time * 60);
$avercps = ($Grand_total / $seconds);
print "Average CPS   = $avercps \n\n";
print "Program has ended\n\n";


-- 
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: formatting database text

2002-02-05 Thread Chas Owens

On Tue, 2002-02-05 at 12:29, Hughes, Andrew wrote:
> I have created a news article database where non-technical people can cut
> and paste articles to be stored in a mySQL database table.  Everything
> works.  However when I display these in a browser, I want to have  class="whatever"> tags around each paragraph, so that the non-technical
> people do not have to worry about adding these tags.  I was thinking the
> logic would go something like this:
> 
> When displaying the body field of the database, before anything else print
> 
> 
> Then, for each blank line print 
> 
> Finally, after the last paragraph print 
> 
> Should I do this when the articles go into or are pulled out of the
> database?
> How do I go about doing this?
> 
> All suggestions are welcome.
> 
> Thanks,
> Andrew
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

You should really use  instead of , and consider using
something like (warning not tested):


$in_para = 0;
foreach (split '\n', $text) {
if (/^\s*$/) { #if blank line or only white space
if ($in_para) {
$in_para = 0;
print "\n";
}
print "\n";
} else {
unless ($in_para) {
$in_para = 1;
print "\n";
}
print "$_\n";
}
}
print "\n" if ($in_para);



-- 
Today is Boomtime the 37th day of Chaos in the YOLD 3168


Missle Address: 33:48:3.521N  84:23:34.786W


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




Re: formatting database text

2002-02-05 Thread Chas Owens

On Tue, 2002-02-05 at 12:29, Hughes, Andrew wrote:
> I have created a news article database where non-technical people can cut
> and paste articles to be stored in a mySQL database table.  Everything
> works.  However when I display these in a browser, I want to have  class="whatever"> tags around each paragraph, so that the non-technical
> people do not have to worry about adding these tags.  I was thinking the
> logic would go something like this:
> 
> When displaying the body field of the database, before anything else print
> 
> 
> Then, for each blank line print 
> 
> Finally, after the last paragraph print 
> 
> Should I do this when the articles go into or are pulled out of the
> database?
> How do I go about doing this?
> 
> All suggestions are welcome.
> 
> Thanks,
> Andrew
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]

You should really use  instead of , and consider using
something like (warning not tested):


$in_para = 0;
foreach (split '\n', $text) {
if (/^\s*$/) { #if blank line or only white space
if ($in_para) {
$in_para = 0;
print "\n";
}
print "\n";
} else {
unless ($in_para) {
$in_para = 1;
print "\n";
}
print "$_\n";
}
}
print "\n" if ($in_para);



-- 
Today is Boomtime the 37th day of Chaos in the YOLD 3168


Missle Address: 33:48:3.521N  84:23:34.786W


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




Re: Formatting with printf

2002-01-10 Thread Scott

On Wed, 9 Jan 2002, John W. Krahn wrote:
> printf is based on the C language printf function and can be a bit
> tricky.  The format "%-5s" will not truncate a value longer than 5
> characters but it will pad a shorter value with spaces.  To truncate a
> longer value use the format "%-5.5s".  Also, the variable @fields[14] is
> an array slice, you want a scalar $fields[14].
> printf( NEWQUOTES "%-5.5s", $fields[14] );

Thank you John and everyone else.  The .5 worked.

-Scott



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




Re: Formatting with printf

2002-01-09 Thread John W. Krahn

Scott wrote:
> 
> Hi all.

Hello,

> I have a couple of strings that I need to format.  One of those fields is
> a alpha/numeric string.  Here is the code:
> 
> printf NEWQUOTES ("%-5s", @fields[14]);
> 
> When I run the code I get 10 extra spaces before the next field instead of
> the 5.  The value of @fields[14] is:  A2103.

printf is based on the C language printf function and can be a bit
tricky.  The format "%-5s" will not truncate a value longer than 5
characters but it will pad a shorter value with spaces.  To truncate a
longer value use the format "%-5.5s".  Also, the variable @fields[14] is
an array slice, you want a scalar $fields[14].

printf( NEWQUOTES "%-5.5s", $fields[14] );


> Is there a problem with the value being alpha/numeric?

No.


John
-- 
use Perl;
program
fulfillment

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




RE: Formatting with printf

2002-01-09 Thread Bob Showalter

> -Original Message-
> From: Scott [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, January 09, 2002 10:29 AM
> To: [EMAIL PROTECTED]
> Subject: Formatting with printf
> 
> 
> Hi all.
> 
> I have a couple of strings that I need to format.  One of 
> those fields is
> a alpha/numeric string.  Here is the code:
> 
> printf NEWQUOTES ("%-5s", @fields[14]);
> 
> When I run the code I get 10 extra spaces before the next 
> field instead of
> the 5.  The value of @fields[14] is:  A2103.
>

As an aside, you should use $fields[14], not @fields[14].
For an explanation of why, run your script like this:

   perl -Mdiagnostics -w myscript.pl >/dev/null

But that's not explaining the spaces. If you are getting
spaces printed after A2103, they must be in the value in
$fields[14]. The width specifier of 5 sets only a minimum
width, not a maximum. If you want exactly 5 columns to be
output, with longer values truncated, you can use:

   %-5.5s

> Is there a problem with the value being alpha/numeric?

No.

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




Re: Formatting with printf

2002-01-09 Thread Scott

Cancel the request.  The field coming in actually had 10 spaces in it, so
I just removed the spaces doing this:

$field14 = @fields[14];
$field14 =~ s/ //g; 
print NEWQUOTES ($field14);


On Wed, 9 Jan 2002, Scott wrote:
> printf NEWQUOTES ("%-5s", @fields[14]);
> When I run the code I get 10 extra spaces before the next field instead of
> the 5.  The value of @fields[14] is:  A2103.
> Is there a problem with the value being alpha/numeric?


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




RE: formatting text

2001-09-19 Thread Najamuddin, Junaid

Hi,

# Define your fields
my($fld1, $fld2, $fld3, $fld4, $fld5, $fld6, $fld7, $fld8);

# load fields in array which are separated by pipe delimit
foreach $val1(@arr1) # referring to values in array
{($fld1, $fld2, $fld3, $fld4, $fld5, $fld6, $fld7, $fld8) =
split(/\|/,"$val1");

# Print the selected fields
print " $fld4,  '$fld3'($fld2)\n";

I hope I have answered your question
Take care
junaid

-Original Message-
From: Edward [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, September 19, 2001 11:34 AM
To: [EMAIL PROTECTED]
Subject: formatting text


Hi ,
I'm trying to extract clients with Lost-Carrier as Terminate-Cause from a
raw radius file.
I'm interested in 2 fields. User-name and Terminate Cause.
On running my script. I get a full list of all client User-names. and those
with Termiante-Cause.
Can some one assist me


 "One cannot guess the real difficulties of a problem before having solved
it."


-- 
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: Formatting text

2001-08-28 Thread Randal L. Schwartz

> "Mike" == Mike Rapuano <[EMAIL PROTECTED]> writes:

Mike> I was searching for a diff-like perl tool for NT and came
Mike> accross this persons code. Worked well for me.

You might look at Algorithm::Diff, and especially the magazine column
I wrote on that.  The advantage over the [snipped] code is that it
finds the best fit, not just a sequential match that can get lost.

See .

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




Re: Formatting text

2001-08-28 Thread Aravindan . Sundaram


Hope you have a file which contains these lines,

Just check below code :

$File = "sample.txt";

open(IN,"<$File");

while()
{
 $_ =~ s/\x0d//g;

 if( $_ =~ m/play/i )
 {
  $Result = "";
  while( $_ =~ /.{0,5}play.{0,5}/i  )
  {
   $Result .= $`;
   $Temp = $&;
   $_ = $';

   print $Temp."\n";

   $Result .= $Temp;
  }
  $Result .= $_;
  $_ = $Result;
 }
}
close(IN);

bye
aravind
System Executive
eFunds International India Pvt. Ltd.
8272628, Ext. 4593


> > 1. What should I do , if I want to read each line
> of
> > text with the "search word". Should I put the
> > occurence of search word in an array ? (I'm not so
> > sure).

> > 2. If I want to read the string, provided only a
> > certain length (for e.g., 5 words to the LEFT of
> > "search word" & 5 words to the RIGHT of "search
> > word"). Is there a range to declare but how to
> detect
> > the starting point and end point for each
> occurence?
>



This  electronic  mail  message is intended solely for the named recipients
and may contain confidential and proprietary business information of eFunds
Corporation  and  all its subsidiaries.   If you are not a named recipient,
please notify the sender immediately.  You may not disclose the contents to
any  other person; use this electronic mail message or its contents for any
other purpose; or further store or copy its contents in any medium.



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




RE: Formatting text

2001-08-28 Thread Mike Rapuano

HI all -- 

I was searching for a diff-like perl tool for NT and came accross this
persons code. Worked well for me.

Mike


-Original Message-
From: Gibbs Tanton - tgibbs [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 28, 2001 10:34 AM
To: 'Najamuddin, Junaid '; '[EMAIL PROTECTED] '
Subject: RE: Formatting text


 
If you are on a unix system...you can just say diff file1 file2.  On
Windows
there is probably something comparable.
-Original Message-
From: Najamuddin, Junaid
To: [EMAIL PROTECTED]
Sent: 8/28/2001 9:18 AM
Subject: Formatting text

Hi,
Here is my script, I am comparing two txt files which are pipe delimited
line by line if they match then their is no output but if they do not
match then it gives an output about the difference 
My both files are loaded in the array and I am comparing line by line
How can I compare a value in a certain field within an array line by
line between two files so that I can have result I want 
instead of comparing whole line
The txt files are attached for your visual ease they are not pipe
delimited and the field names are displayed, In the script they will be
pipe delimited without any field name or header
If you can help me out
thanks
 
 
my($snapshot, $baseline);  # Defining txt files 
 
# First file
$snapshot = "./302-snap.txt"; # List of Svcs currently running loc at
c:\perl
 
# Second file
$baseline = "./302-base.txt";  # List of All Svcs which should be
running
 
my(@arr1, @arr2, @result);  # Defining arrays
my($fld1, $fld2, $fld3, $fld4); # Defining variables for fields
my($match, $cnt, $val1, $val2, $finalresult); # Defining scalar
variables
$match = "N"; 
 
#Open snapshot file and insert every line into @arr1
open(SNAPSHOT, $snapshot) or die "Unable to open $snapshot."; # Open the
txt file and place it in filehandle
 
$cnt = 0;
while (  ) # Looping thru the filehandle snapshot
 {
 $arr1[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (SNAPSHOT); # close the filehandle snapshot
 
#Open baseline file and insert every line into @arr2
open(BASELINE, $baseline) or die "Unable to open $baseline."; # Open the
txt file and place it in filehandle 
 
$cnt = 0;
while (  ) # Looping thru the filehandle baseline
{
 $arr2[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (BASELINE); # close filehandle baseline
 
# Outer loop is for baseline file
# Inner loop is for snapshot file
# Taking one element from @arr2 (baseline) and comparing it with all the
elements in @arr1(snapshot) and 
# If their is no match then insert that name into @result.
 
$cnt = 0;
foreach $val2 (@arr2) # referring to baseline
{
 foreach $val1 (@arr1) # referring to snapshot
 {
  if ($val1 eq $val2) 
  {
   $match = "Y";
  }
 }
 if  ($match eq "N") 
 {
  $result[$cnt] = $val2;
  $cnt = $cnt + 1;
 }
 
 $match = "N";
 }
 
$finalresult = 0; # initializing to zero
foreach $val1 (@result)
{
 $finalresult = $finalresult + 1;
}
 
if ($finalresult >  0 ) 
{
 print "\nList of SICK Siebel-Components \n\n"; # If some svc is not
functioning
 foreach $val1 (@result)
 {
  ($fld1,$fld2,$fld3,$fld4) =  split(/\|/,"$val1");# separating req
fields for output
  print "Svc-Component $fld4, of Siebel-Svc '$fld3'($fld2)\n";
  
 }
}
else
{
 print "\nAll Siebel-Components are Functioning Fine\n"; # When all svcs
are running fine
}

 
 <<302-base.txt>>  <<302-snap.txt>>  <> 

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


 cdiff.pl

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


RE: Formatting text

2001-08-28 Thread Najamuddin, Junaid

Sorry I forgot about the platform
It is on Windows NT platform
thanks

-Original Message-
From: Gibbs Tanton - tgibbs [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, August 28, 2001 9:34 AM
To: 'Najamuddin, Junaid '; '[EMAIL PROTECTED] '
Subject: RE: Formatting text


 
If you are on a unix system...you can just say diff file1 file2.  On Windows
there is probably something comparable.
-Original Message-
From: Najamuddin, Junaid
To: [EMAIL PROTECTED]
Sent: 8/28/2001 9:18 AM
Subject: Formatting text

Hi,
Here is my script, I am comparing two txt files which are pipe delimited
line by line if they match then their is no output but if they do not
match then it gives an output about the difference 
My both files are loaded in the array and I am comparing line by line
How can I compare a value in a certain field within an array line by
line between two files so that I can have result I want 
instead of comparing whole line
The txt files are attached for your visual ease they are not pipe
delimited and the field names are displayed, In the script they will be
pipe delimited without any field name or header
If you can help me out
thanks
 
 
my($snapshot, $baseline);  # Defining txt files 
 
# First file
$snapshot = "./302-snap.txt"; # List of Svcs currently running loc at
c:\perl
 
# Second file
$baseline = "./302-base.txt";  # List of All Svcs which should be
running
 
my(@arr1, @arr2, @result);  # Defining arrays
my($fld1, $fld2, $fld3, $fld4); # Defining variables for fields
my($match, $cnt, $val1, $val2, $finalresult); # Defining scalar
variables
$match = "N"; 
 
#Open snapshot file and insert every line into @arr1
open(SNAPSHOT, $snapshot) or die "Unable to open $snapshot."; # Open the
txt file and place it in filehandle
 
$cnt = 0;
while (  ) # Looping thru the filehandle snapshot
 {
 $arr1[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (SNAPSHOT); # close the filehandle snapshot
 
#Open baseline file and insert every line into @arr2
open(BASELINE, $baseline) or die "Unable to open $baseline."; # Open the
txt file and place it in filehandle 
 
$cnt = 0;
while (  ) # Looping thru the filehandle baseline
{
 $arr2[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (BASELINE); # close filehandle baseline
 
# Outer loop is for baseline file
# Inner loop is for snapshot file
# Taking one element from @arr2 (baseline) and comparing it with all the
elements in @arr1(snapshot) and 
# If their is no match then insert that name into @result.
 
$cnt = 0;
foreach $val2 (@arr2) # referring to baseline
{
 foreach $val1 (@arr1) # referring to snapshot
 {
  if ($val1 eq $val2) 
  {
   $match = "Y";
  }
 }
 if  ($match eq "N") 
 {
  $result[$cnt] = $val2;
  $cnt = $cnt + 1;
 }
 
 $match = "N";
 }
 
$finalresult = 0; # initializing to zero
foreach $val1 (@result)
{
 $finalresult = $finalresult + 1;
}
 
if ($finalresult >  0 ) 
{
 print "\nList of SICK Siebel-Components \n\n"; # If some svc is not
functioning
 foreach $val1 (@result)
 {
  ($fld1,$fld2,$fld3,$fld4) =  split(/\|/,"$val1");# separating req
fields for output
  print "Svc-Component $fld4, of Siebel-Svc '$fld3'($fld2)\n";
  
 }
}
else
{
 print "\nAll Siebel-Components are Functioning Fine\n"; # When all svcs
are running fine
}

 
 <<302-base.txt>>  <<302-snap.txt>>  <> 

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




RE: Formatting text

2001-08-28 Thread Gibbs Tanton - tgibbs

 
If you are on a unix system...you can just say diff file1 file2.  On Windows
there is probably something comparable.
-Original Message-
From: Najamuddin, Junaid
To: [EMAIL PROTECTED]
Sent: 8/28/2001 9:18 AM
Subject: Formatting text

Hi,
Here is my script, I am comparing two txt files which are pipe delimited
line by line if they match then their is no output but if they do not
match then it gives an output about the difference 
My both files are loaded in the array and I am comparing line by line
How can I compare a value in a certain field within an array line by
line between two files so that I can have result I want 
instead of comparing whole line
The txt files are attached for your visual ease they are not pipe
delimited and the field names are displayed, In the script they will be
pipe delimited without any field name or header
If you can help me out
thanks
 
 
my($snapshot, $baseline);  # Defining txt files 
 
# First file
$snapshot = "./302-snap.txt"; # List of Svcs currently running loc at
c:\perl
 
# Second file
$baseline = "./302-base.txt";  # List of All Svcs which should be
running
 
my(@arr1, @arr2, @result);  # Defining arrays
my($fld1, $fld2, $fld3, $fld4); # Defining variables for fields
my($match, $cnt, $val1, $val2, $finalresult); # Defining scalar
variables
$match = "N"; 
 
#Open snapshot file and insert every line into @arr1
open(SNAPSHOT, $snapshot) or die "Unable to open $snapshot."; # Open the
txt file and place it in filehandle
 
$cnt = 0;
while (  ) # Looping thru the filehandle snapshot
 {
 $arr1[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (SNAPSHOT); # close the filehandle snapshot
 
#Open baseline file and insert every line into @arr2
open(BASELINE, $baseline) or die "Unable to open $baseline."; # Open the
txt file and place it in filehandle 
 
$cnt = 0;
while (  ) # Looping thru the filehandle baseline
{
 $arr2[$cnt] = $_;
 $cnt = $cnt + 1;
  } 
  close (BASELINE); # close filehandle baseline
 
# Outer loop is for baseline file
# Inner loop is for snapshot file
# Taking one element from @arr2 (baseline) and comparing it with all the
elements in @arr1(snapshot) and 
# If their is no match then insert that name into @result.
 
$cnt = 0;
foreach $val2 (@arr2) # referring to baseline
{
 foreach $val1 (@arr1) # referring to snapshot
 {
  if ($val1 eq $val2) 
  {
   $match = "Y";
  }
 }
 if  ($match eq "N") 
 {
  $result[$cnt] = $val2;
  $cnt = $cnt + 1;
 }
 
 $match = "N";
 }
 
$finalresult = 0; # initializing to zero
foreach $val1 (@result)
{
 $finalresult = $finalresult + 1;
}
 
if ($finalresult >  0 ) 
{
 print "\nList of SICK Siebel-Components \n\n"; # If some svc is not
functioning
 foreach $val1 (@result)
 {
  ($fld1,$fld2,$fld3,$fld4) =  split(/\|/,"$val1");# separating req
fields for output
  print "Svc-Component $fld4, of Siebel-Svc '$fld3'($fld2)\n";
  
 }
}
else
{
 print "\nAll Siebel-Components are Functioning Fine\n"; # When all svcs
are running fine
}

 
 <<302-base.txt>>  <<302-snap.txt>>  <> 

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




Re: Formatting text

2001-08-24 Thread Curtis Poe

--- Michael Fowler <[EMAIL PROTECTED]> wrote:
> On Fri, Aug 24, 2001 at 12:23:17PM -0700, Curtis Poe wrote:
> > --- [EMAIL PROTECTED] wrote:
> > This is such a common problem that "use strict 'system'" is being
> > considered for Perl 6.
> 
> Hm, I don't remember any discussion on that one, but perhaps I missed
> something.

I don't know how widely that was discussed.  Damian Conway was here in Portland a 
couple of weeks
ago giving a prospectus on Perl 6 and that was one of the issues he mentioned.

Cheers,
Curtis Poe

=
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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




Re: Formatting text

2001-08-24 Thread Michael Fowler

On Fri, Aug 24, 2001 at 12:23:17PM -0700, Curtis Poe wrote:
> --- [EMAIL PROTECTED] wrote:
> This is such a common problem that "use strict 'system'" is being
> considered for Perl 6.

Hm, I don't remember any discussion on that one, but perhaps I missed
something.

Regardless, you don't need to wait until Perl 6 for similar functionality. 
Perl has as standard, since at least Perl 5.005, the Fatal module.

use Fatal qw(:void open);
open(FILE, ">/etc/passwd");

*KABOOM*

Or, you can use it to do your checking for you (the above only does a check
if open is called in void context):

use Fatal qw(open);
open(FILE, ">/etc/passwd");

*KABOOM* 


Granted, it's not as simple as use strict 'system', but you can pretty
easily write a pragma or module to effectively do that for you.  You could
even patch strict.pm to do it, just don't expect it to get adopted into core
(strict's stricture are frozen, AFAIK).


Michael
--
Administrator  www.shoebox.net
Programmer, System Administrator   www.gallanttech.com
--

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




RE: Formatting text

2001-08-24 Thread Curtis Poe

--- [EMAIL PROTECTED] wrote:
> This is going off of two assumptions, 1) that you want the task number to be
> unique and 2) the fields are supposed to be tab delimited. If you want to
> remove the dups from a different column then make that column as the key to
> the hash. As for which fields, you can add and remove any column from the
> value of the hash. Hope this helps.
>  
>  
> open FILE, "file";
> open OUT, ">outfile";

Without really checking out the rest of the code, I see a problem here.

What happens if 'file' or 'outfile' don't exist?  This code will silently fail and 
tracking down
the bug could be a pain if this is embedded in a large system.  This is such a common 
problem that
"use strict 'system'" is being considered for Perl 6.  With this, the script would 
automatically
die if someone forgets to check the return value of a system call.  The above code is 
better
written as:

open FILE, "$file" or die "Can't open $file for reading: $!";
open OUT, "> $outfile" or die "Can't open $outfile for writing: $!";

I know, I know, I can hear the protests already:  "but Ovid, you're just being 
anal-retentive. 
This programmer *knows* the files are there."

That's a frequent rebuttal, but if you work with Perl for any length of time, you're 
likely to
have many programs just lying around.  I've repeatedly seen people get bitten by this 
when they
reorganize directories, migrate their scripts to new boxes, or simply get rid of 
'unnecessary'
files to save some disk space.  It takes so little work up from to save so much pain 
later.

Cheers,
Curtis Poe

=
Senior Programmer
Onsite! Technology (http://www.onsitetech.com/)
"Ovid" on http://www.perlmonks.org/

__
Do You Yahoo!?
Make international calls for as low as $.04/minute with Yahoo! Messenger
http://phonecard.yahoo.com/

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




  1   2   >