Re: FW: Win32::AdminMisc

2004-03-12 Thread R. Joseph Newton
"Meneses, Alden" wrote:

> Was able to download from www.roth.net

Please don't top-post.  Better to PPM for it.  That tool is built into the
ActiveState distribution.  You might wish to add a couple sites to the
repository:
rep add Jenda http://Jenda.Krynicky.cz/perl
rep add Roth http://www.roth.net/perl/packages/
rep add UWinnipeg http://theoryx5.uwinnipeg.ca/cgi-bin/ppmserver?urn:/PPMServer
since the ActiveState sites are missing a lot of useful modules

Joseph



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




RE: Print Format Problem

2004-03-12 Thread Charles K. Clarkson
Jeff Borders <[EMAIL PROTECTED]> wrote:
: 
: 
: I thought the "~" would take care of this in format, but no. I've also
: tried using printf without a format block, but couldn't figure out how
: to left justify the strings.

[snip]

: # Print Format Definitions
: 
: format STDOUT =
: @<@<
@<
: $name,$name,$name
: @<@<
@<

It looks like the tilde (~) goes on the format line, not the variable
line.

~ @<@<
@<

[snip]


HTH,

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


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




Re: not getting the syntax

2004-03-12 Thread R. Joseph Newton
Charlotte Hee wrote:

>
> For a single record I can see how that works but let's say I have
> 4 or 5 employees and I have the employee information for each one
> (assumed). Now I want to build a record for each employee in a loop like
> this:
>
>   @names = ('Jason','Aria','Samir','Owen');
>
>   foreach $na ( @names ) {

So all the records differ only in name, and all other parameters stay the same?

> $record = {
>   NAME   => $na,
>   EMPNO  => $emp_no,
>   TITLE  => $title,
>   AGE=> $age,
>   SALARY => $salary,
>   PALS   => [ $friend_list ],
> };
>
> # store record
>  $byname{ $record->{NAME} } = $record;
>
>  }
>
> Now I want to add something later, after the record for the employee has
> been created. For example, I want to add the phone for Owen.
> When I try the following I get "can't use undefined value...".

Since you don't seem to be showing us the code you are actually using, we are
somewhat at a disadvantage.  ONe thing you should not, though.  Since the nested
hashes should be storedonly by reference, you should use the derefereing operator
-> to get at least the fianl element.

>  $byname{ Owen }{ PHONE } = '999-';

Should be:
$byname{ Owen }->{ PHONE } = '999-';
are you using strict?  The code above should cause an error, not just an
uninitialized variable warning.  You really should put:
use strict;
use warnings;
at the top of the script, and clean up the errors returned before you try to take
on multidimensional structure problems.  Houses built on sand cannot be expected
to stand.

Joseph


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




Re: help with a regex and greediness

2004-03-12 Thread R. Joseph Newton
Stuart White wrote:

> Wow, yeah that helps a lot.
> Here's a question: If if had:
> $line = 'Spurs 94, Suns 82, Heat 99, Magic 74'
>  and then did a split on comma and comma's surrounding
> spaces:
> @result = split (/\s*,\s*/, $line);

result?  How specific is "result" to the issue at hand?  Would not $score

>
> then @result would look like this, right?
> @result[0] = 'Spurs 94'

You should know better than this by now, with the help you've been getting.
With that @ symbol, you are referring to a slice--an array of one element.  ***
When you are referring to a scalar, use the scalar symbol $ ***

>
> @result[1] = 'Suns 82'

These first two make sense, pretty much.  I think this is one place where $team1
and $team2 might be more sensible, though it is even better, if there is some
order to which team is listed first in the pairing, to have you identifier
reflect that order, say $home_team and $visitor [if these are accurate of
course]

>
> @result[2] = 'Heat 99'

Going on to load more elements into the array does not make sense..  Does your
data come in one continuous line, just a long string of team names separated by
commas?  My impression is that it came line by line.  There would be no sense in
doing the work of the split only to throw everything back in the same pile.
There are a lot of different things you could do here, but the sensible ones
would indicate that you should do something with the stats for each pairing
before you go on to the next line.


>
> @result[3] = 'Magic 74'
>
> If I wanted to split on the numbers as well, why
> doesn't this work:
> @result = split (/\s*\d*,\s*\d*/, $line);

The previous post already explained this, and you have seen the result of what
you are trying.  You can't do that because the information disappears if you use
it in the split expression.

Splitting the lines into a pair of team-score combinations is one step.  It
deserves a line of its own.
Extracting the name and score from each team-score clause is another step that
deserves a line or three of its own.

>
>
> I just had a thought, it have to look more like:
> @result = split (/(\s*|\d*),\s*\d*/, $line);

Unless there is a compelling reason why you must do all your regex work for a
line in one pass, you are better off not doing so.

Though its Perl implementation is highly efficient, the regex process is very
costly, and the cost rises much more through complexity of expression than
through multiple runs.

Please review
perldoc -f split
for a better understanding.  The split regex, is *what gets thrown away*.  Do
not put any data you may need in it.

I think an earlier poster may have confused the issue with the zero-or-more
spaces before the comma.  Unless the file format is very sloppy, this should not
be necessary.  Assume decent data,
split /,\*/, $line;
should split a line into its comma delimited elements.  Nor reason to try to get
fancy here.  Just split on the comma to get two elements.

>
> I'm confusing myself, but when I get home, I'll try
> out what you've shown me.  That might be the way to do
> it.
>

Keep it grounded--by choosing identifiers carefully to always communicate
clearly what information they hold
Keep it simple--most things are, if you let them be.
Do one thing per line until you are using all of the basic constructs fluently.
Pay close attention to the nature of each thing you are using a variable to
describe, and make the containment class symbol [$, @, or %] that you use,
reflects accurately whether you are referring to a container, or to an element
held in the container.

Joseph


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




Print Format Problem

2004-03-12 Thread Jeff Borders
I've written a trivial program to print avery labels.  One that allows
me to specify how many rows to print (when I don't need 30 labels).

The problem is that I don't want to print a blank line on a 3 line
label.

I thought the "~" would take care of this in format, but no.  I've also
tried using printf without a format block, but couldn't figure out how
to left justify the strings.

My label format  is:

Name
(PO Box or Suite, if needed)  <--this is the blank line.
Address
City, State  Zip

Below is my program.

!/usr/bin/perl

use strict;
use warnings;

my (
$name,
$address,
$address2,
$citystatezip,
$label_rows,
$skip_rows,
$line_feeds,
);

$line_feeds="\n\n\n\n";

# Print label on Avery 5160 sheet
# of labels.  (3x10)

# Skip missing labels where I've already
# printed.
print "\nEnter How Many Rows to Skip: ";
chomp($skip_rows = );

# Only print the rows I need.  Save the rest
# for another run.
print "\nEnter How Many Rows to Print: ";
chomp($label_rows = );

print "\nEnter recipient name: ";
chomp($name=);

print "\nEnter address: ";
chomp($address=);

print "\nEnter P.O Box or Suite [None]: ";
chomp($address2=);
# Check for a PO Box or Suite Number
if ($address2=~/\w/) 
{
$line_feeds="\n\n\n"
}
print "\nEnter city, state  zip: ";
chomp($citystatezip=);


# Print Format Definitions

format STDOUT =
@<  @<  
@<
$name,  $name,  $name
@<  @<  
@<
~ $address2,$address2,  $address2
@<  @<  
@<
$address,   $address,   $address
@<  @<  
@<
$citystatezip,  $citystatezip,  $citystatezip
.

while ( $label_rows > 0 )
{
if ( $skip_rows > 0 ) 
{
$skip_rows=-$skip_rows; 
}
else{
write;  
$label_rows=$label_rows - 1;
}   
print $line_feeds;
}




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




chown-ing symlink

2004-03-12 Thread Ohad Ohad
chown seems to be able only to follow links and change the destination.

Anyway to change the link itself, I wouldn't want to run system("chown -h 
$file") . . .

I'm using various unix machine (Linux, SunOs etc.)

_
Tired of spam? Get advanced junk mail protection with MSN 8. 
http://join.msn.com/?page=features/junkmail

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



Re: can somebody tell me what this means

2004-03-12 Thread R. Joseph Newton
sam lehman wrote:


> so would:
> something ? dosomething : somethingelse ? dosomethingelse : killyourself
> be the same as

Let's not go there--at least not yet.  NOt that I object to suicide
particularly, y'know "dff'runt strokes fer diff'runt folks" an' all, but nesting
conditionals before you have used them properly is not good.

Your speculation below is probably correct, but it is probably not a good use
for your time.  Better to learn how to put it to use than to seek for ways to
abuse it.

>
> if (something){

indent properly, please.

>
>dosomething();
> } elsif (somethingelse){
>dosomethingelse();
> }else{
>killyourself();
> }

For more complicated situations like that presented here, it is much better to
use the second form shown.  I would also recommend the formatting changes shown,
since they make it much more viually clear that this is a complex contidional as
opposed to a series of discrete conditionals that just happen to occur in
sequence.

Joseph


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




Re: not getting the syntax

2004-03-12 Thread John W. Krahn
Charlotte Hee wrote:
> 
> On Thu, 11 Mar 2004, John W. Krahn wrote:
> >
> > Charlotte Hee wrote:
> > >
> > > I tried the following but it doesn't work and gives an error.
> > >
> > >  $byname { $record->{"Jason"}->PHONE } = '999-'; # error undefined val
> > >
> > > I keep looking at the syntax but it's not sinking in.
> >
> > Or to access it via the %byname hash:
> >
> > $byname{ Jason }{ PHONE } = '999-';
> 
> For a single record I can see how that works but let's say I have
> 4 or 5 employees and I have the employee information for each one
> (assumed). Now I want to build a record for each employee in a loop like
> this:
> 
>   @names = ('Jason','Aria','Samir','Owen');
> 
>   foreach $na ( @names ) {
> 
> $record = {
>   NAME   => $na,
>   EMPNO  => $emp_no,
>   TITLE  => $title,
>   AGE=> $age,
>   SALARY => $salary,
>   PALS   => [ $friend_list ],
> };
> 
> # store record
>  $byname{ $record->{NAME} } = $record;
>  }
> 
> Now I want to add something later, after the record for the employee has
> been created. For example, I want to add the phone for Owen.
> When I try the following I get "can't use undefined value...".
> 
>  $byname{ Owen }{ PHONE } = '999-';

I'm sorry but you haven't provided enough context to diagnose the
problem and you left out the rest of the error message.  The line you
provided has three defined strings so that can't be the problem.


John
-- 
use Perl;
program
fulfillment

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




Re: not getting the syntax

2004-03-12 Thread Charlotte Hee


On Thu, 11 Mar 2004, John W. Krahn wrote:

> Date: Thu, 11 Mar 2004 16:33:00 -0800
> From: John W. Krahn <[EMAIL PROTECTED]>
> To: [EMAIL PROTECTED]
> Subject: Re: not getting the syntax
>
> Charlotte Hee wrote:
> >
> > Hello,
>
> Hello,
>
> > I'm looking at the perl cookbook example on how to create a record data
> > type:
> >
> >   $record = {
> > NAME   => "Jason",
> > EMPNO  => 132,
> > TITLE  => "deputy peon",
> > AGE=> 23,
> > SALARY => 37_000,
> > PALS   => [ "Norbert", "Rhys", "Phineas"],
> > };
> >
> > # store record
> > $byname{ $record->{NAME} } = $record;
> >
> > Is it possible to add another key:value-pair to $record  *after*  its
> > already been saved in %byname? For example, if I want to add
> > 'phone => 999-' to $record for Jason. How do I do that?
> >
> > I tried the following but it doesn't work and gives an error.
> >
> >  $byname { $record->{"Jason"}->PHONE } = '999-'; # error undefined val
> >
> > I keep looking at the syntax but it's not sinking in.
>
>
> $record is a reference to a hash so just add it directly to $record:
>
> $record->{ PHONE } = '999-';
>
>
> Or to access it via the %byname hash:
>
> $byname{ Jason }{ PHONE } = '999-';
>
>
>
> John
> --
> use Perl;
> program
> fulfillment
>
> --
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
>
>
>


For a single record I can see how that works but let's say I have
4 or 5 employees and I have the employee information for each one
(assumed). Now I want to build a record for each employee in a loop like
this:

  @names = ('Jason','Aria','Samir','Owen');

  foreach $na ( @names ) {

$record = {
  NAME   => $na,
  EMPNO  => $emp_no,
  TITLE  => $title,
  AGE=> $age,
  SALARY => $salary,
  PALS   => [ $friend_list ],
};

# store record
 $byname{ $record->{NAME} } = $record;

 }

Now I want to add something later, after the record for the employee has
been created. For example, I want to add the phone for Owen.
When I try the following I get "can't use undefined value...".

 $byname{ Owen }{ PHONE } = '999-';


thanks, Chee

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




Re: second-level string interpolation

2004-03-12 Thread Michael C. Davis
Thanks everyone for the great ideas.



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




reading .ini values

2004-03-12 Thread Meneses, Alden
Ok.. Thanks to everyone's help. Here is the script I ended up with.

use Win32::AdminMisc;

$file = 'c:\temp\lurecover.txt';
open (OUT, ">>$file") || die "cannot append $file: $!";
my $pcnames = 'ACME0001';
for ( my $pcname = 0; $pcname<3000; $pcname++) {
$lupath = "$pcnames\\admin\$\\W2HCM.INI";
print OUT "$pcnames ";
$lu = Win32::AdminMisc::ReadINI( $lupath , "MS SNANT" , "Term" );
print OUT "$lu \n";
$pcnames++;
}
close (OUT) || die "can't close $file:$!";

-Original Message-
From: Meneses, Alden 
Sent: Friday, March 12, 2004 12:59 PM
To: [EMAIL PROTECTED]
Subject: RE: How do I increment a alphanumeric value?


Did anyone metion that you guys are good.

I see my mistake. I didn't separate the 2 variables. I really need to
read up on my programming. :)

I will post my final script that everyone has generously helped me with.

Thanks again.


-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, March 12, 2004 12:24 PM
To: Meneses, Alden; [EMAIL PROTECTED]
Subject: RE: How do I increment a alphanumeric value?


Meneses, Alden wrote:
> I must be doing something wrong with this script
> 
> my $pcname = 'ACME0001';
> while ( $pcname < 5 ) {
I believe it has to do the arithmetic < which is making ACME0001
into 0 which then gets added to 0.

This is the code I used to verify it would work as stated:
my $MyIds = 'ACME0001';
for(my $MyId=0;$MyId<1300;$MyId++) {
printf "%s\n", $MyIds++;
 }
 Wags ;)
> print "$pcname \n";
> $pcname++;
> }
> 
> I get these results
> 
> ACME0001
> 1
> 2
> 3
> 4
> 
> -Original Message-
> From: Wagner, David --- Senior Programmer Analyst --- WGO
> [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 12, 2004 11:50 AM
> To: James Edward Gray II; Meneses, Alden
> Cc: [EMAIL PROTECTED]
> Subject: RE: How do I increment a alphanumeric value?
> 
> 
> James Edward Gray II wrote:
>> On Mar 12, 2004, at 1:39 PM, Meneses, Alden wrote:
>> 
>>> Suppose I have machines that are ACME
>>> 
>>> I want to go from ACME0001 to ACME
>> 
>> How's this?
>   If you have it in a variable then you only need ++ to get to the
next 
> item:
>   my $MyMachines = 'ACME0001';
> 
>   # to get the next item
>   $MyMachines++;
> 
>   Seems to simple, but ran a test and it works just like that.
> 
> Wag ;)
>> 
>> foreach (1..) {
>>  printf "ACME%4d\n", $_;
>> }
>> 
>> James


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



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



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




Re: second-level string interpolation

2004-03-12 Thread david
Randy W. Sims wrote:

> I just realized that this might be a little misleading. If you break it
> down to:
> 
> my $result = eval $header;
> print $result;
> 
> You will get an uninitialized value error. What happens is that
> 
> eval $header
> 
> is first interpolated to
> 
> eval { # File: xyz }
> 
> which is executed as perl code. As perl code this is a comment and so
> produces no value, so $result ends up with no value, which is then
> printed in the next line, generating the uninitialized value error.

i think you have the right idea but your example is a little "misleading", 
consider:

[panda]# perl -W -le 'print eval "#"'

[panda]# perl -W -le 'print eval {"#"}'
#

similiarly, now consider:

[panda]# perl -W -le 'print eval undef'
Use of uninitialized value in eval "string" at -e line 1.
Use of uninitialized value in print at -e line 1.

[panda]# perl -W -le 'print eval "undef"'
Use of uninitialized value in print at -e line 1.

[panda]# perl -W -le 'print eval {"undef"}'
undef

* we got 2 warnings for the first try because undef is evaluated once and 
then returned again to print

* we got 1 warning because undef is returned from eval

* we got no warnings for the last try because the string undef is returned 
from eval

* eval{'#'} returns # not undef so your example above will not return undef

* eval EXPR vs. eval BLOCK can be found at perldoc -f eval

david
-- 
s$s*$+/http://learn.perl.org/> 




Re: date format using localtime()

2004-03-12 Thread Owen Cook

On Fri, 12 Mar 2004, Jeff Westman wrote:

> Is there a way in perl to get the month/day/year using localtime
> WITHOUT using 'use POSIX qw(strftime)' or a system "date" call.
> 
> Something using slices, maybe something like:
> 
>   print scalar ((localtime(time))[4,3,7])
> 
> expecting the result to be 03122004.

Try something like this;

---
#!/usr/bin/perl

use strict;
use warnings;

my @t = localtime(time);
print (sprintf("%02d%02d%04d",$t[4] +1,$t[3],$t[5] +1900));



Owen


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




Re: date format using localtime()

2004-03-12 Thread Steve Mayer
Jeff,

  Check out
  http://www.users.voicenet.com/~corr/macsupt/macperl/localtime.html

Steve

On Fri, Mar 12, 2004 at 01:38:28PM -0800, Jeff Westman wrote:
> Is there a way in perl to get the month/day/year using localtime
> WITHOUT using 'use POSIX qw(strftime)' or a system "date" call.
> 
> Something using slices, maybe something like:
> 
>   print scalar ((localtime(time))[4,3,7])
> 
> expecting the result to be 03122004.
> 
> Trivial question, thanks in advance.
> 
> 
> Jeff
> 
> __
> Do you Yahoo!?
> Yahoo! Search - Find what you?re looking for faster
> http://search.yahoo.com
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>  
> 
> 

=
Steve Mayer Oracle Corporation
Project Lead1211 SW 5th Ave.
Portland Development Center Suite 900
[EMAIL PROTECTED]   Portland, OR 97204 
Phone:  503-525-3127
=

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




Re: [Fwd: Re: Regular expression to replace whitespace with comma]

2004-03-12 Thread Jan Eden

Distribution Lists wrote:

>
>Thanks but I've that already try that
>
>C:\temp>perl -pi.bak -e "s/\s+/,/g" tempfile.out
>
>C:\temp>more < tempfile.out
>Server,Drive,FSTYPE,Size,Free,Used,SERVER1,C$,NTFS,4095,296,3799,SERVER1,D$,NTFS
>,4001,1908,2093,SERVER1,C$,NTFS,38123,29808,8315,
>
>The only thing that is missing is that after field 6 there is no comma,
>but a newline
>
>So that it will come out like this
>
>Server,Drive,FSTYPE,Size,Free,Used
>SERVER1,C$,NTFS,4095,296,3799
>SERVER2,D$,NTFS,4001,1908,2093
>SERVER3,C$,NTFS,38123,29812,8315
>
Ok, so use a character class:

s/[ \t]+/,/g;

(mind the space in front of the tab inside the character class)

HTH,

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

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




date format using localtime()

2004-03-12 Thread Jeff Westman
Is there a way in perl to get the month/day/year using localtime
WITHOUT using 'use POSIX qw(strftime)' or a system "date" call.

Something using slices, maybe something like:

  print scalar ((localtime(time))[4,3,7])

expecting the result to be 03122004.

Trivial question, thanks in advance.


Jeff

__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

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




Re: Regular expression to replace whitespace with comma

2004-03-12 Thread Distribution Lists
That worked great!
Thanks Darryl
> On Mar 12, 2004, at 3:19 PM, Distribution Lists wrote:
>
>> Thanks but I've that already try that
>>
>> C:\temp>perl -pi.bak -e "s/\s+/,/g" tempfile.out
>
> Add the -l switch to that to chomp the newline and replace it when it
> prints:
>
> perl -pli.bak -e "s/\s+/,/g" tempfile.out
>
> James
>
>> C:\temp>more < tempfile.out
>> Server,Drive,FSTYPE,Size,Free,Used,SERVER1,C$,NTFS,4095,296,3799,SERVER
>> 1,D$,NTFS,4001,1908,2093,SERVER1,C$,NTFS,38123,29808,8315,
>>
>> The only thing that is missing this the new line after field 6
>>
>> So that it will come out like this
>>
>> Server,Drive,FSTYPE,Size,Free,Used
>> SERVER1,C$,NTFS,4095,296,3799
>> SERVER2,D$,NTFS,4001,1908,2093
>> SERVER3,C$,NTFS,38123,29812,8315
>
>
> --
> 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: Regular expression to replace whitespace with comma

2004-03-12 Thread James Edward Gray II
On Mar 12, 2004, at 3:19 PM, Distribution Lists wrote:

Thanks but I've that already try that

C:\temp>perl -pi.bak -e "s/\s+/,/g" tempfile.out
Add the -l switch to that to chomp the newline and replace it when it  
prints:

perl -pli.bak -e "s/\s+/,/g" tempfile.out

James

C:\temp>more < tempfile.out
Server,Drive,FSTYPE,Size,Free,Used,SERVER1,C$,NTFS,4095,296,3799,SERVER 
1,D$,NTFS,4001,1908,2093,SERVER1,C$,NTFS,38123,29808,8315,

The only thing that is missing this the new line after field 6

So that it will come out like this

Server,Drive,FSTYPE,Size,Free,Used
SERVER1,C$,NTFS,4095,296,3799
SERVER2,D$,NTFS,4001,1908,2093
SERVER3,C$,NTFS,38123,29812,8315


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



[Fwd: Re: Regular expression to replace whitespace with comma]

2004-03-12 Thread Distribution Lists


Thanks but I've that already try that

C:\temp>perl -pi.bak -e "s/\s+/,/g" tempfile.out

C:\temp>more < tempfile.out
Server,Drive,FSTYPE,Size,Free,Used,SERVER1,C$,NTFS,4095,296,3799,SERVER1,D$,NTFS,4001,1908,2093,SERVER1,C$,NTFS,38123,29808,8315,

The only thing that is missing is that after field 6 there is no comma,
but a newline

So that it will come out like this

Server,Drive,FSTYPE,Size,Free,Used
SERVER1,C$,NTFS,4095,296,3799
SERVER2,D$,NTFS,4001,1908,2093
SERVER3,C$,NTFS,38123,29812,8315



> On Mar 12, 2004, at 2:55 PM, Distribution Lists wrote:
>
>> Can someone please tell what regular expression would change
>>
>> Server   Drive   FSTYPE   Size  Free  Used
>> SERVER1  C$   NTFS4095   296  3799
>> SERVER2  D$   NTFS4001  1908  2093
>> SERVER3  C$   NTFS   38123 29811  8312
>>
>> to
>>
>> Server,Drive,FSTYPE,Size,Free,Used
>> SERVER1,C$,NTFS,4095,296,3799
>> SERVER2,D$,NTFS,4001,1908,2093
>> SERVER3,C$,NTFS,38123,29812,8312
>
> s/\s+/,/g;
>
> James
>
>


-- 




-- 


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




Re: second-level string interpolation

2004-03-12 Thread Randy W. Sims
On 03/12/04 16:08, Randy W. Sims wrote:

To elaborate a bit, the reason for the failure is that while the string 
is interpolated, it is then also evaluated as perl code, so in

my $header = <<'end_of_header';
# File: $filename
end_of_header
my $filename = 'xyz';

print eval $header;

the last statement ends up looking something like:

print # File: xyz;

I just realized that this might be a little misleading. If you break it 
down to:

my $result = eval $header;
print $result;
You will get an uninitialized value error. What happens is that

eval $header

is first interpolated to

eval { # File: xyz }

which is executed as perl code. As perl code this is a comment and so 
produces no value, so $result ends up with no value, which is then 
printed in the next line, generating the uninitialized value error.

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



Re: second-level string interpolation

2004-03-12 Thread John W. Krahn
"Michael C. Davis" wrote:
> 
> Hi, Apologies if I'm bringing up a repeated topic.   I searched the list
> archive and the web and nothing specific has turned up so far.
> 
> Is there a way to defer evaluation of the contents of a here-doc-defined
> value such that one can embed variables in the here-doc and not have them
> evaluated until they are used later?  Something like this:


perldoc -q "How can I expand variables in text strings"



John
-- 
use Perl;
program
fulfillment

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




Re: second-level string interpolation

2004-03-12 Thread Randy W. Sims
On 03/12/04 16:35, david wrote:
Michael C. Davis wrote:


Is there a way to defer evaluation of the contents of a here-doc-defined
value such that one can embed variables in the here-doc and not have them
evaluated until they are used later?  Something like this:
   code:
   -
   use strict;
   use warnings;
   my $header = <<'end_of_header';
   # File: $filename
   end_of_header
   my $filename = 'xyz';
   print $header, "\n"; # output: want to see # File: xyz, but get #
   File:
$filename
I tried a few variations and nothing seems to work, as shown below.  (This
RFC http://dev.perl.org/perl6/rfc/229.html from Perl 6 implies that there
is fact no way to do this.)  Can anyone clarify.  Thank you.


i didn't check the link but from what you describe, i don't see any reason 
this can't be done:

#!/usr/bin/perl -w
use strict;
my $s =<<'CODE';
I want to say: $v
CODE
my $v = 'hello world';

print eval qq.qq,$s,.;

__END__

prints:

I want to say: hello world

david
To elaborate a bit, the reason for the failure is that while the string 
is interpolated, it is then also evaluated as perl code, so in

my $header = <<'end_of_header';
# File: $filename
end_of_header
my $filename = 'xyz';

print eval $header;

the last statement ends up looking something like:

print # File: xyz;

which of course generates an error. The solution as David points out is 
to surround $header with double quotes. There are several ways to do this:

$header = '"' . $header . '"'; # double quote the string in $header
print eval $header;
-or-

print eval "\"$header\"";

-or-

print eval "qq($header)";

-or-

print eval qq("$header");

etc.

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



Re: Regular expression to replace whitespace with comma

2004-03-12 Thread James Edward Gray II
On Mar 12, 2004, at 2:55 PM, Distribution Lists wrote:

Can someone please tell what regular expression would change

Server   Drive   FSTYPE   Size  Free  Used
SERVER1  C$   NTFS4095   296  3799
SERVER2  D$   NTFS4001  1908  2093
SERVER3  C$   NTFS   38123 29811  8312
to

Server,Drive,FSTYPE,Size,Free,Used
SERVER1,C$,NTFS,4095,296,3799
SERVER2,D$,NTFS,4001,1908,2093
SERVER3,C$,NTFS,38123,29812,8312
s/\s+/,/g;

James

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



RE: How do I increment a alphanumeric value?

2004-03-12 Thread Meneses, Alden
Did anyone metion that you guys are good.

I see my mistake. I didn't separate the 2 variables. I really need to
read up on my programming. :)

I will post my final script that everyone has generously helped me with.

Thanks again.


-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, March 12, 2004 12:24 PM
To: Meneses, Alden; [EMAIL PROTECTED]
Subject: RE: How do I increment a alphanumeric value?


Meneses, Alden wrote:
> I must be doing something wrong with this script
> 
> my $pcname = 'ACME0001';
> while ( $pcname < 5 ) {
I believe it has to do the arithmetic < which is making ACME0001
into 0 which then gets added to 0.

This is the code I used to verify it would work as stated:
my $MyIds = 'ACME0001';
for(my $MyId=0;$MyId<1300;$MyId++) {
printf "%s\n", $MyIds++;
 }
 Wags ;)
> print "$pcname \n";
> $pcname++;
> }
> 
> I get these results
> 
> ACME0001
> 1
> 2
> 3
> 4
> 
> -Original Message-
> From: Wagner, David --- Senior Programmer Analyst --- WGO 
> [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 12, 2004 11:50 AM
> To: James Edward Gray II; Meneses, Alden
> Cc: [EMAIL PROTECTED]
> Subject: RE: How do I increment a alphanumeric value?
> 
> 
> James Edward Gray II wrote:
>> On Mar 12, 2004, at 1:39 PM, Meneses, Alden wrote:
>> 
>>> Suppose I have machines that are ACME
>>> 
>>> I want to go from ACME0001 to ACME
>> 
>> How's this?
>   If you have it in a variable then you only need ++ to get to the
next 
> item:
>   my $MyMachines = 'ACME0001';
> 
>   # to get the next item
>   $MyMachines++;
> 
>   Seems to simple, but ran a test and it works just like that.
> 
> Wag ;)
>> 
>> foreach (1..) {
>>  printf "ACME%4d\n", $_;
>> }
>> 
>> James


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



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




RE: second-level string interpolation

2004-03-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Michael C. Davis wrote:
> Hi, Apologies if I'm bringing up a repeated topic.   I searched the
> list archive and the web and nothing specific has turned up so far.
> 
> Is there a way to defer evaluation of the contents of a
> here-doc-defined value such that one can embed variables in the
> here-doc and not have them evaluated until they are used later? 
> Something like this: 
> 
When you need to do something like that, I give them names like: 

Then do a $header =~ s//$filename/gi;  at the point you want to do 
the print.
Now if doing more than once, then would wnat to put into secondardy variable 
to do the changes.


> code:
> -
> use strict;
> use warnings;
> 
> my $header = <<'end_of_header';
> # File: $filename
#File: 

> end_of_header
> 
> my $filename = 'xyz';
 $header =~ s//$filename/gi;
> print $header, "\n"; # output: want to see # File: xyz, but get #
> File: $filename

The reason you are getting $filename in this instance has to do with using 
single ' vs double ". If double had been used then  you would have had:
File: 

Wags ;)
> 
> 
> I tried a few variations and nothing seems to work, as shown below. 
> (This RFC http://dev.perl.org/perl6/rfc/229.html from Perl 6 implies
> that there is fact no way to do this.)  Can anyone clarify.  Thank
> you. 
> 
> code:
> -
> use strict;
> use warnings;
> 
> my $header = <<'end_of_header';
> # File: $filename
> end_of_header
> 
> my $filename = "test";
> 
> print $header, "\n";
> print eval { "$header" }, "\n";
> print "$header", "\n";
> 
> print eval { $header }, "\n";
> print ((eval $header) ."\n");
> 
> output [ .. editted for readability .. ]:
> ---
> 
> # File: $filename
> # File: $filename
> # File: $filename
> # File: $filename
> Use of uninitialized value in concatenation (.) or string at
> ..\perlt\testevalsimple.pl line 15.



  Any questions and/or problems, please let me know.

  Thanks.

Wags ;)
Int: 9-8-002-2224
Ext: 408-323-4225x2224



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



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




Regular expression to replace whitespace with comma

2004-03-12 Thread Distribution Lists
Can someone please tell what regular expression would change

Server   Drive   FSTYPE   Size  Free  Used
SERVER1  C$   NTFS4095   296  3799
SERVER2  D$   NTFS4001  1908  2093
SERVER3  C$   NTFS   38123 29811  8312

to

Server,Drive,FSTYPE,Size,Free,Used
SERVER1,C$,NTFS,4095,296,3799
SERVER2,D$,NTFS,4001,1908,2093
SERVER3,C$,NTFS,38123,29812,8312

Thanks

-- 


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




Re: Reading text file in reverse order

2004-03-12 Thread John W. Krahn
"R. Joseph Newton" wrote:
> 
> "John W. Krahn" wrote:
> >
> > use File::ReadBackwards;
> >
> > tie *FILE, 'File::ReadBackwards', $file
> > or die "Cannot open $file: $!";
> >
> > while (  ) {
> > chomp;
> > print scalar reverse, "\n";
> > }
> >
> > __END__
> 
> Looks cool, and perfectly tailored to the task.  How is it for handligg 
> muti-charcter newlines?

The documentation states that this is handled correctly.

perldoc File::ReadBackwards
[snip]
DESCRIPTION
   This module reads a file backwards line by line. It is
   simple to use, memory efficient and fast. It supports both
   an object and a tied handle interface.

   It is intended for processing log and other similar text
   files which typically have their newest entries appended
   to them. By default files are assumed to be plain text and
   have a line ending appropriate to the OS. But you can set
   the input record separator string on a per file basis.



John
-- 
use Perl;
program
fulfillment

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




Re: second-level string interpolation

2004-03-12 Thread david
Michael C. Davis wrote:

> 
> Is there a way to defer evaluation of the contents of a here-doc-defined
> value such that one can embed variables in the here-doc and not have them
> evaluated until they are used later?  Something like this:
> 
> code:
> -
> use strict;
> use warnings;
> 
> my $header = <<'end_of_header';
> # File: $filename
> end_of_header
> 
> my $filename = 'xyz';
> print $header, "\n"; # output: want to see # File: xyz, but get #
> File:
> $filename
> 
> 
> I tried a few variations and nothing seems to work, as shown below.  (This
> RFC http://dev.perl.org/perl6/rfc/229.html from Perl 6 implies that there
> is fact no way to do this.)  Can anyone clarify.  Thank you.

i didn't check the link but from what you describe, i don't see any reason 
this can't be done:

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

my $s =<<'CODE';
I want to say: $v
CODE

my $v = 'hello world';

print eval qq.qq,$s,.;

__END__

prints:

I want to say: hello world

david
-- 
s$s*$+/http://learn.perl.org/> 




second-level string interpolation

2004-03-12 Thread Michael C. Davis
Hi, Apologies if I'm bringing up a repeated topic.   I searched the list
archive and the web and nothing specific has turned up so far.

Is there a way to defer evaluation of the contents of a here-doc-defined
value such that one can embed variables in the here-doc and not have them
evaluated until they are used later?  Something like this:

code:
-
use strict;
use warnings;

my $header = <<'end_of_header';
# File: $filename
end_of_header

my $filename = 'xyz';
print $header, "\n"; # output: want to see # File: xyz, but get # File:
$filename


I tried a few variations and nothing seems to work, as shown below.  (This
RFC http://dev.perl.org/perl6/rfc/229.html from Perl 6 implies that there
is fact no way to do this.)  Can anyone clarify.  Thank you.

code:
-
use strict;
use warnings;

my $header = <<'end_of_header';
# File: $filename
end_of_header

my $filename = "test";

print $header, "\n";
print eval { "$header" }, "\n";
print "$header", "\n";

print eval { $header }, "\n";
print ((eval $header) ."\n");

output [ .. editted for readability .. ]:
---

# File: $filename
# File: $filename
# File: $filename
# File: $filename
Use of uninitialized value in concatenation (.) or string at
..\perlt\testevalsimple.pl line 15.


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




RE: How do I increment a alphanumeric value?

2004-03-12 Thread Charles K. Clarkson
Wagner, David --- Senior Programmer Analyst --- WGO
<[EMAIL PROTECTED]> wrote:
: 
: Meneses, Alden wrote:
: > I must be doing something wrong with this script
: > 
: > my $pcname = 'ACME0001';
: > while ( $pcname < 5 ) {
:   I believe it has to do the arithmetic < which is making 
: ACME0001 into 0 which then gets added to 0.
: 
: This is the code I used to verify it would work as stated:
: my $MyIds = 'ACME0001';
: for(my $MyId=0;$MyId<1300;$MyId++) {
: printf "%s\n", $MyIds++;
:  }

Hmmm,

{
local $\ = "\n";
print foreach 'ACME0001' .. 'ACME1300';
}


HTH,

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


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




RE: How do I increment a alphanumeric value?

2004-03-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Meneses, Alden wrote:
> I must be doing something wrong with this script
> 
> my $pcname = 'ACME0001';
> while ( $pcname < 5 ) {
I believe it has to do the arithmetic < which is making ACME0001 into 0 which 
then gets added to 0.

This is the code I used to verify it would work as stated:
my $MyIds = 'ACME0001';
for(my $MyId=0;$MyId<1300;$MyId++) {
printf "%s\n", $MyIds++;
 }
 Wags ;)
> print "$pcname \n";
> $pcname++;
> }
> 
> I get these results
> 
> ACME0001
> 1
> 2
> 3
> 4
> 
> -Original Message-
> From: Wagner, David --- Senior Programmer Analyst --- WGO
> [mailto:[EMAIL PROTECTED]
> Sent: Friday, March 12, 2004 11:50 AM
> To: James Edward Gray II; Meneses, Alden
> Cc: [EMAIL PROTECTED]
> Subject: RE: How do I increment a alphanumeric value?
> 
> 
> James Edward Gray II wrote:
>> On Mar 12, 2004, at 1:39 PM, Meneses, Alden wrote:
>> 
>>> Suppose I have machines that are ACME
>>> 
>>> I want to go from ACME0001 to ACME
>> 
>> How's this?
>   If you have it in a variable then you only need ++ to get to the
> next item:
>   my $MyMachines = 'ACME0001';
> 
>   # to get the next item
>   $MyMachines++;
> 
>   Seems to simple, but ran a test and it works just like that.
> 
> Wag ;)
>> 
>> foreach (1..) {
>>  printf "ACME%4d\n", $_;
>> }
>> 
>> James


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



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




RE: How do I increment a alphanumeric value?

2004-03-12 Thread Meneses, Alden
I must be doing something wrong with this script

my $pcname = 'ACME0001';
while ( $pcname < 5 ) {
print "$pcname \n";
$pcname++;
}

I get these results

ACME0001
1
2
3
4

-Original Message-
From: Wagner, David --- Senior Programmer Analyst --- WGO
[mailto:[EMAIL PROTECTED] 
Sent: Friday, March 12, 2004 11:50 AM
To: James Edward Gray II; Meneses, Alden
Cc: [EMAIL PROTECTED]
Subject: RE: How do I increment a alphanumeric value?


James Edward Gray II wrote:
> On Mar 12, 2004, at 1:39 PM, Meneses, Alden wrote:
> 
>> Suppose I have machines that are ACME
>> 
>> I want to go from ACME0001 to ACME
> 
> How's this?
If you have it in a variable then you only need ++ to get to the
next item:
my $MyMachines = 'ACME0001';

# to get the next item
$MyMachines++;

Seems to simple, but ran a test and it works just like that.

Wag ;)
> 
> foreach (1..) {
>   printf "ACME%4d\n", $_;
> }
> 
> James



  Any questions and/or problems, please let me know.

  Thanks.

Wags ;)
Int: 9-8-002-2224
Ext: 408-323-4225x2224



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



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




Way to create Windows Services.

2004-03-12 Thread Viraj Purang
Is there a PERL API 
using which I can create wrapper windows services around 
batch files.

I need to be able to stop and start a set of Java commands.

People in my company have already made start scripts for these Java
commands.

However the stop scripts and /or APIs that would STOP Java processes
 were never made and I do not have any idea about how 
I am going to stopping these processes.

Viraj B. Purang
Arzoon Inc.


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




RE: How do I increment a alphanumeric value?

2004-03-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
James Edward Gray II wrote:
> On Mar 12, 2004, at 1:39 PM, Meneses, Alden wrote:
> 
>> Suppose I have machines that are ACME
>> 
>> I want to go from ACME0001 to ACME
> 
> How's this?
If you have it in a variable then you only need ++ to get to the next item:
my $MyMachines = 'ACME0001';

# to get the next item
$MyMachines++;

Seems to simple, but ran a test and it works just like that.

Wag ;)
> 
> foreach (1..) {
>   printf "ACME%4d\n", $_;
> }
> 
> James



  Any questions and/or problems, please let me know.

  Thanks.

Wags ;)
Int: 9-8-002-2224
Ext: 408-323-4225x2224



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



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




Re: How do I increment a alphanumeric value?

2004-03-12 Thread James Edward Gray II
On Mar 12, 2004, at 1:39 PM, Meneses, Alden wrote:

Suppose I have machines that are ACME

I want to go from ACME0001 to ACME
How's this?

foreach (1..) {
printf "ACME%4d\n", $_;
}
James

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



How do I increment a alphanumeric value?

2004-03-12 Thread Meneses, Alden
Suppose I have machines that are ACME

I want to go from ACME0001 to ACME


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




RE: Read from tape device

2004-03-12 Thread Jakob Kofoed
Hi again,

Sorry for the delayed answer.

Thank you for all your comments (Yes Joseph, I will try to enhance my basic
abilities - sorry for the bad code:-)

My thoughts on this project was to make a perl script which copy the content
of a tape to disk, no matter if it is tar archives, binary files, EBCDIC and
so on, much like the UNIX tcopy. But, I work on Linux and don't have the
tcopy available.

When you write multiple files to a tape it creates an physical "end of file
marker" at the end of each file. When some applications write to tape they
make an EOF between each file and then a double EOF at the end of the tape.

So, the idea was to stream out the data in a unaltered form to disk,
creating a new file each time perl finds a EOF marker.

I tried to use the binmode function, fx:

binmode STDOUT;
open BIN, "< $ARGV[0]";
open OUT, "> perltest.bin";
binmode BIN, ":raw:";
print OUT ;
close BIN;
close OUT;

That give the all the content on the tape into one file.

In conjunction with this I used the "read" function, but here I have to give
a block size - and since the block size varies it does not work well! Fx one
of the file types have a 3200 bit EBCDIC header followed by 400 byte binary
header and the rest of the file can have any byte size. This means that I
would have to chose 1 as block size to get everything out with "read", and
that is a time consuming task (please correct me if I am wrong).

I also looked at the "eof" function and tried to test the filehandle on this
but with no luck.

If you have any clues or suggestions I would really appreciate it.

Thanks again,
Jakob


-Oprindelig meddelelse-
Fra: David le Blanc [mailto:[EMAIL PROTECTED]
Sendt: 12. marts 2004 02:18
Til: R. Joseph Newton; [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Emne: RE: Read from tape device


> -Original Message-
> From: R. Joseph Newton [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, 10 March 2004 5:37 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: Read from tape device
> 
> [EMAIL PROTECTED] wrote:
> 
> > Hi All,
> >
> > I am trying to read some data from af unix tape device. The 
> have several files with "end of file markers". Can I read 
> from tape devices at all?
> >
> > I tried "open" on the device and this one reads all files 
> on the tape into the first file and then hangs. Is it my code 
> (I know the first loop is not very good:-) or does perl not 
> recognise or honer the EOF marks?
> >
> > Thanks,
> > Jakob
> >
> > my $cnt = 0;
> > while (1 == 1) {
> > open IN, "<", "/dev/nst0" || die "cant open ...\n";
> > while (@out = ) {
> 
> Why are you using an array?. That puts the read operator in 
> list context, so that it reads all lines of the file into the 
> @out array on the first round through the loop.
> 

Isn't this a perfect example of when you should be using
RECORD based I/O?

What is the tape block size?

> >
> > $cnt++;
> 
> Please use vowels.  They are neither poisonous nor explosive.
> 
> >
> > open OUT, ">", "$cnt.bin" || die "cant open out\n";
> > print OUT "@out\n";
> > close OUT;
> > }
> > }
> > close IN;
> [snip]

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


FW: Win32::AdminMisc

2004-03-12 Thread Meneses, Alden
Was able to download from www.roth.net

-Original Message-
From: Meneses, Alden 
Sent: Friday, March 12, 2004 10:41 AM
To: [EMAIL PROTECTED]
Subject: Win32::AdminMisc


I'm getting this error when I try to execute this script

use Win32::AdminMisc;
path$="\\cpws0073\winnt\W2HCM.INI"
LU$=ReadINI( path$ [, "MS SNANT" [, "Term"}})
print LU$


Can't locate Win32/AdminMisc.pm in @INC (@INC contains: C:\Program
Files\ActiveState Komodo 2.5 C:/Perl/lib C:/Perl/site/lib .)

I thought Win32 is automatically included with ActivePerl.

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




Win32::AdminMisc

2004-03-12 Thread Meneses, Alden
I'm getting this error when I try to execute this script

use Win32::AdminMisc;
path$="\\cpws0073\winnt\W2HCM.INI"
LU$=ReadINI( path$ [, "MS SNANT" [, "Term"}})
print LU$


Can't locate Win32/AdminMisc.pm in @INC (@INC contains: C:\Program
Files\ActiveState Komodo 2.5 C:/Perl/lib C:/Perl/site/lib .)

I thought Win32 is automatically included with ActivePerl.

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




RE: Improving performance when working with large text files

2004-03-12 Thread West, William M




>
>Price, Jason wrote:
>> I'm trying to optimize a script used for processing large text log
>> files (around 45MB).  I think I've got all the processing fairly well
>> optimized, but I'm wondering if there's anything I can do to speed up
>> the initial loading of the file.

oh the pain and suffering of regular expressions!!  oh the forests of
slashes, both forward and backwards!!  but reading these things is only the
start of the pain!!  

imagine looking for something like m/BOB\d*\wyoyo/g # but what if in that
 line there were SEVERAL cases where a number was followed by a letter? that
greedy little '*' would take your processor through a little roller coaster
ride!!pain.  :P  well, i've been learning and asking about that too->  
by slurping the WHOLE file into memory at once (do you have room to but a 45
megabyte file into memory?)  the speed of the processing went up- but lots
and LOTS of time has been saved (still working on it though :)  ) by doing
this::m/BOB\d*?\wyoyo/g #  the '?' tells the regular expression to use
'*' to look at only the next nearest match - lot's of processor time saved!!

but even better than that??

perldoc -q regex optomize

or some other string to search for-  also www.perldoc.com -> type perlre in 
its search box.


willy

ps -  regular expressions are neat, if braindamaging.

pps- i just reread the question and realized that he was interested in
reading the file in faster!!  ok::

undef$/;#kills the 'line delimiter'-> maybe "local $/= undef;" in 
#a subroutine is safer

open FH, "filetoparse";

$foo = ; #one variable holding 45 megabytes of stuff! is that ok? or is
 # $foo not quite a regular ol' scaler?

while (/$regular_expression_pattern/){
do_stuff_with ($1,$2,$3,$4)

}

# have fun!!

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




RE: Improving performance when working with large text files

2004-03-12 Thread Bob Showalter
Price, Jason wrote:
> I'm trying to optimize a script used for processing large text log
> files (around 45MB).  I think I've got all the processing fairly well
> optimized, but I'm wondering if there's anything I can do to speed up
> the initial loading of the file.
> 
> Currently, I'm performing operations on the file one line at a time,
> using a "while ()" loop.  I'm pushing important lines into an
> array, so further processing is done in memory, but the initial pass
> on the file is rather time consuming.  Is there a more efficient way
> to work with large text files?

Since the file is line-oriented, what you're doing looks like the best way
to me. You can play around with the stdio buffering using
IO::Handle::setbuf(), but I doubt that will help much.

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




Re: how to make sure, that the script is running one time?

2004-03-12 Thread Randal L. Schwartz
> "Christian" == Christian Stalp <[EMAIL PROTECTED]> writes:

Christian> I have a question regarding process-control. I want to
Christian> write a perl script which must not running in more than one
Christian> process in the same time. The script creates a directory
Christian> copys a zip-file in it, unpack it and reads every file in
Christian> this package. However, the files must not get opened by
Christian> another process.  How can I make sure, that my perl-scipt
Christian> runs only in one process, or eaysier, is there a function
Christian> "flock" which blocks a whole directory and not only a
Christian> single file?

See "There Can Be Only One (the HIGHLANDER solution)" at
.

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




Install Curses for Bastille Install

2004-03-12 Thread Paul Kraus
When ever I try and install Curses

Perl -MCPAN -e "install Cures" its fails. I can't seem to figure out why.
This is on a brand new install of fedora core 1.

Here is the output Long
---
CPAN: Storable loaded ok
Going to read /root/.cpan/Metadata
  Database was generated on Thu, 11 Mar 2004 22:50:06 GMT
Running install for module Curses
Running make for W/WP/WPS/Curses-1.06.tar.gz
CPAN: Digest::MD5 loaded ok
Checksum for /root/.cpan/sources/authors/id/W/WP/WPS/Curses-1.06.tar.gz ok
Scanning cache /root/.cpan/build for sizes
Curses-1.06/
Curses-1.06/hints/
Curses-1.06/hints/c-MSWin32.visualc.h
Curses-1.06/hints/c-sunos.bsd.h
Curses-1.06/hints/c-dec_osf.h
Curses-1.06/hints/c-svr4.h
Curses-1.06/hints/c-darwin.h
Curses-1.06/hints/c-none.h
Curses-1.06/hints/c-freebsd.ncurses.h
Curses-1.06/hints/c-aix.h
Curses-1.06/hints/c-linux.bsd.h
Curses-1.06/hints/c-irix.ncurses.h
Curses-1.06/hints/c-dgux.h
Curses-1.06/hints/c-bsd386.h
Curses-1.06/hints/c-MSWin32.borland.h
Curses-1.06/hints/c-hpux.h
Curses-1.06/hints/c-irix.bsd.h
Curses-1.06/hints/c-solaris.h
Curses-1.06/hints/c-bsdos.h
Curses-1.06/hints/c-dynixptx.h
Curses-1.06/hints/c-isc.h
Curses-1.06/hints/c-openbsd.h
Curses-1.06/hints/c-cygwin.h
Curses-1.06/hints/c-linux.ncurses.h
Curses-1.06/hints/c-sunos.sysv.h
Curses-1.06/hints/c-next.h
Curses-1.06/hints/c-sco.h
Curses-1.06/hints/c-os2.ncurses.h
Curses-1.06/hints/c-vms.h
Curses-1.06/hints/c-sunos.ncurses.h
Curses-1.06/hints/c-netbsd.h
Curses-1.06/hints/c-freebsd.bsd.h
Curses-1.06/gdc
Curses-1.06/demo.panel
Curses-1.06/gen/
Curses-1.06/gen/make.list.syms
Curses-1.06/gen/make.CursesBoot.c
Curses-1.06/gen/make.CursesFun.c
Curses-1.06/gen/make.Curses.pm
Curses-1.06/gen/make.CursesVar.c
Curses-1.06/gen/list.typ
Curses-1.06/gen/make.CursesCon.c
Curses-1.06/gen/list.fun
Curses-1.06/gen/increase-version
Curses-1.06/gen/make.CursesTyp.h
Curses-1.06/gen/list.con
Curses-1.06/gen/list.var
Curses-1.06/gen/README
Curses-1.06/gen/Gen.pm
Curses-1.06/demo
Curses-1.06/demo.menu
Curses-1.06/list.syms
Curses-1.06/demo.form
Curses-1.06/cdemo.c
Curses-1.06/CursesFun.c
Curses-1.06/Makefile.PL
Curses-1.06/CursesVar.c
Curses-1.06/Curses.pm
Curses-1.06/CursesCon.c
Curses-1.06/Curses.c
Curses-1.06/CursesTyp.h
Curses-1.06/test.syms
Curses-1.06/Artistic
Curses-1.06/MANIFEST
Curses-1.06/testtyp.c
Curses-1.06/testsym.c
Curses-1.06/README
Curses-1.06/CursesBoot.c
Curses-1.06/demo2
Curses-1.06/testint.c
Curses-1.06/Copying
Curses-1.06/INSTALL
Removing previously used /root/.cpan/build/Curses-1.06

  CPAN.pm: Going to build W/WP/WPS/Curses-1.06.tar.gz

GENsupport: not applicable
PANELS support: not enabled
MENUS  support: not enabled
FORMS  support: not enabled

Making a guess for $inc and/or $libs...
Making a guess for "c-config.h"...
Checking if your kit is complete...
Looks good
Writing Makefile for Curses
cp Curses.pm blib/lib/Curses.pm
/usr/bin/perl test.syms   
function 'waddch' found
function 'wechochar' found
function 'waddchstr' found
function 'waddchnstr' found
function 'waddstr' found
function 'waddnstr' found
function 'wattroff' found
function 'wattron' found
function 'wattrset' found
function 'wstandend' found
function 'wstandout' found
function 'wattr_get' found
function 'wattr_off' found
function 'wattr_on' found
function 'wattr_set' found
function 'wchgat' found
function 'COLOR_PAIR' found
function 'PAIR_NUMBER' found
function 'beep' found
function 'flash' found
function 'wbkgd' found
function 'wbkgdset' found
function 'getbkgd' found
function 'wborder' found
function 'box' found
function 'whline' found
function 'wvline' found
function 'werase' found
function 'wclear' found
function 'wclrtobot' found
function 'wclrtoeol' found
function 'start_color' found
function 'init_pair' found
function 'init_color' found
function 'has_colors' found
function 'can_change_color' found
function 'color_content' found
function 'pair_content' found
function 'wdelch' found
function 'wdeleteln' found
function 'winsdelln' found
function 'winsertln' found
function 'wgetch' found
function 'ungetch' found
function 'has_key' found
function 'KEY_F' found
function 'wgetstr' found
function 'wgetnstr' found
function 'getyx' found
function 'getparyx' found
function 'getbegyx' found
function 'getmaxyx' found
function 'winch' found
function 'winchstr' found
function 'winchnstr' found
function 'initscr' found
function 'endwin' found
function 'isendwin' found
function 'newterm' found
function 'set_term' found
function 'delscreen' found
function 'cbreak' found
function 'cbreak' returns int
function 'nocbreak' found
function 'nocbreak' returns int
function 'echo' found
function 'echo' returns int
function 'noecho' found
function 'noecho' returns int
function 'halfdelay' found
function 'intrflush' found
function 'keypad' found
function 'meta' found
function 'nodelay' found
function 'notimeout' found
function 'raw' found
function 'raw' returns int
function 'noraw' found
function 'noraw' returns int
function 'qiflush' found
function 'noqiflush' found
f

Re: Improving performance when working with large text files

2004-03-12 Thread Shiping Wang
At 07:55 PM 3/11/2004 -0600, James Edward Gray II wrote:
On Mar 11, 2004, at 10:41 AM, Price, Jason wrote:

I'm trying to optimize a script used for processing large text log files
(around 45MB).  I think I've got all the processing fairly well optimized,
but I'm wondering if there's anything I can do to speed up the initial
loading of the file.
Currently, I'm performing operations on the file one line at a time, using a
"while ()" loop.  I'm pushing important lines into an array, so
further processing is done in memory, but the initial pass on the file is
rather time consuming.  Is there a more efficient way to work with large
text files?
If you post the script, we might me able to give some helpful suggestions.

James
 Hi, I do have similar situation, say I have text a file with 5000 columns 
and 3000 rows. I need to subset the data about 20 columns to a file( total 
~250 files) according to another file tell me where do I cut the columns. 
What is the best strategy to do this? Read whole file into AOA then cut it 
or use while(<>). So far I use while(<>) approach, it's working, but slow.

Thanks,

Shiping

Here is code:

#!/usr/local/bin/perl
use warnings;
use strict;
use Math::Matrix;
use File::Basename;
### open input file for further process ###
if (@ARGV < 2){
die "Usage: $0 CutRegion MarkerData $!";
exit(0);
}
my %region;
open (Region, "$ARGV[0]") or die $!;
while (){
chomp;
my ($start, $end) = split;
$region{$start} = $end;
# print "$start => $region{$start}\n";
}
close Region;
my @nonMarkVar;

my $inData = $ARGV[1];
open (nonMarkdata, "$inData") or die "No such file or wrong file 
name!";
while (){
chomp;
my @tmp = (split/\s+/)[0..4];
push @nonMarkVar, [EMAIL PROTECTED];
}
close nonMarkdata;

my $cnt4ext;

foreach my $key (sort {$a <=> $b} keys %region){
my @getback;
my $first = $key + 4;
my $last = $region{$key} + 4;
my @Markers;
open (Markdata, "$inData") or die "No such file or wrong file name!";
while (){
chomp;
my @tmp2 = (split/\s+/)[$first..$last];
push @Markers, [EMAIL PROTECTED];
}
close Markdata;
++$cnt4ext;
my $basename = basename($inData,".txt");
my $outfile = $basename.'.'.$cnt4ext;
my @fruit;
open (outH, ">$outfile") or die "Can not create outfile!";
print "Processing data: Marker column $key - 
$region{$key}, output to $outfile\n";
#sleep (1);
my @trans = transpose([EMAIL PROTECTED]);
my @b4final;
foreach my $j (@trans) {
my @conv = char2num([EMAIL PROTECTED]);
push @b4final, [EMAIL PROTECTED];
}
my @transback = transpose([EMAIL PROTECTED]);
# put non marker data part and marker data back together;

my $x = new Math::Matrix (@nonMarkVar);
my $y = new Math::Matrix (@transback);
my $m = $x->concat($y);
@fruit = $m;
@fruit = sort { $b->[4] <=> $a->[4] } @fruit;
foreach my $j ([EMAIL PROTECTED]) {
print outH join " ", @{$j}, "\n";
}
close outH;
}
### subroutine to transpose matrix ###;
sub transpose {
transpose columns into rows..
}
sub char2num{
convert char to num
}


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



Re: how to make sure, that the script is running one time?

2004-03-12 Thread James Edward Gray II
On Mar 12, 2004, at 9:06 AM, Christian Stalp wrote:

Hello together,
I have a question regarding process-control. I want to write a perl 
script
which must not running in more than one process in the same time. The 
script
creates a directory copys a zip-file in it, unpack it and reads every 
file in
this package. However, the files must not get opened by another 
process.
How can I make sure, that my perl-scipt runs only in one process, or 
eaysier,
is there a function "flock" which blocks a whole directory and not 
only a
single file?
Step 1, when your script launches, have it create a file in some 
convenient directory.  Maybe call it "LOCK", or something similar.  It 
doesn't need a thing in it, just make a file.

Step 2, if the file already exists when your script launches, have it 
abort with some notification.

Note:  You can, and should, combine the check for the file and creation 
of it with Perl's sysopen() built-in.

You can also go farther, say writing the creating processes' PID to the 
file and using that as a secondary check to make sure the process is 
actually running.  This is starting to be work though of super 
questionable value for a simple script.  Use the proper amount of 
paranoia for your particular case.

Step 3, ensure that your script unlink()s the file on exit.  Perl's END 
{ } blocks are ideal for this.

Hope that helps.

James

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



RE: how to make sure, that the script is running one time?

2004-03-12 Thread Bob Showalter
Christian Stalp wrote:
> Hello together,
> I have a question regarding process-control. I want to write a perl
> script which must not running in more than one process in the same
> time. The script creates a directory copys a zip-file in it, unpack
> it and reads every file in this package. However, the files must not
> get opened by another process. 

Are you extracting the files just to read through them? Why not just extract
to a pipe and read the data from that? Then you can avoid creating the files
in the first place?

> How can I make sure, that my perl-scipt runs only in one process

This is typically done by acquiring a lock on a file (usually a "pid" file
that contains the process id number). There's a Proc::PID::File module on
CPAN that looks pretty neat, though I haven't used it personally.

> , or
> eaysier, is there a function "flock" which blocks a whole directory
> and not only a single file?

Not really a way to do that with a lock, and locks are "advisory" only,
depending on your O/S. You might want to play with directory permissions...

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




Re: help with a regex and greediness

2004-03-12 Thread Stuart White

--- "Randy W. Sims" <[EMAIL PROTECTED]>
wrote:
> On 03/12/04 08:18, Stuart White wrote:
> > I like the idea of using split() but decided to
> keep
> > most of my regex and incorporate split on the
> string.
> > So the string: 'Spurs 94, Suns 82' <-and there may
> or
> > may not be a space after the 2.
> > I decided to read up on split(), and then try to
> split
> > it.
> 
> The split function consumes (throws away) the part
> of the string that 
> matches the regular expression used as the first
> argument, so that it no 
> longer appears in the result. For example, let's say
> that
> 
> $line = 'Spurs 94, Suns 82';
> 
> if we use split like
> 
> @result = split /,/, $line;
> 
> I.e. if we split $line on comma, then result will
> contain:
> 
> $result[0] = 'Spurs 94'
> $result[1] = ' Suns 82'
> 
> Notice that the combination of the two elements
> would produce the 
> original string without the comma. In particular,
> notice that a space 
> remains in front of the second element. If we want
> to remove spaces on 
> either side of the comma, we can add it to the regex
> like:
> 
> @result = split /\s*,\s*/, $line;
> 
> which will give us
> 
> $result[0] = 'Spurs 94'
> $result[1] = 'Suns 82'
> 
> Now we can take each of the results and split on a
> space (or any number 
> of spaces) to process each teams score:
> 
> foreach my $teamscore (@result) {
>my ($team,$score) = split /\s+/, $teamscore;
>print "Team: $team, Score: $score\n";
> }
> 
> This would take each of the two elements in @result
> from above in turn 
> and split on one-or-more-spaces, so that the first
> iteration of the loop 
>   would print:
> 
> Team: Spurs, Score: 94
> 
> and the second iteration will produce:
> 
> Team: Suns, Score: 82
> 
> Does that help clarify the way split works?
> 

Wow, yeah that helps a lot.
Here's a question: If if had: 
$line = 'Spurs 94, Suns 82, Heat 99, Magic 74'
 and then did a split on comma and comma's surrounding
spaces:
@result = split (/\s*,\s*/, $line);
then @result would look like this, right?
@result[0] = 'Spurs 94'
@result[1] = 'Suns 82'
@result[2] = 'Heat 99'
@result[3] = 'Magic 74'

If I wanted to split on the numbers as well, why
doesn't this work:
@result = split (/\s*\d*,\s*\d*/, $line);

I just had a thought, it have to look more like:
@result = split (/(\s*|\d*),\s*\d*/, $line);

I'm confusing myself, but when I get home, I'll try
out what you've shown me.  That might be the way to do
it.

> Randy.


__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

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




how to make sure, that the script is running one time?

2004-03-12 Thread Christian Stalp
Hello together,
I have a question regarding process-control. I want to write a perl script 
which must not running in more than one process in the same time. The script 
creates a directory copys a zip-file in it, unpack it and reads every file in 
this package. However, the files must not get opened by another process.
How can I make sure, that my perl-scipt runs only in one process, or eaysier,
is there a function "flock" which blocks a whole directory and not only a 
single file?

Gruss Christian

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




Re: help with a regex and greediness

2004-03-12 Thread Randy W. Sims
On 03/12/04 08:18, Stuart White wrote:
I like the idea of using split() but decided to keep
most of my regex and incorporate split on the string.
So the string: 'Spurs 94, Suns 82' <-and there may or
may not be a space after the 2.
I decided to read up on split(), and then try to split
it.
The split function consumes (throws away) the part of the string that 
matches the regular expression used as the first argument, so that it no 
longer appears in the result. For example, let's say that

$line = 'Spurs 94, Suns 82';

if we use split like

@result = split /,/, $line;

I.e. if we split $line on comma, then result will contain:

$result[0] = 'Spurs 94'
$result[1] = ' Suns 82'
Notice that the combination of the two elements would produce the 
original string without the comma. In particular, notice that a space 
remains in front of the second element. If we want to remove spaces on 
either side of the comma, we can add it to the regex like:

@result = split /\s*,\s*/, $line;

which will give us

$result[0] = 'Spurs 94'
$result[1] = 'Suns 82'
Now we can take each of the results and split on a space (or any number 
of spaces) to process each teams score:

foreach my $teamscore (@result) {
  my ($team,$score) = split /\s+/, $teamscore;
  print "Team: $team, Score: $score\n";
}
This would take each of the two elements in @result from above in turn 
and split on one-or-more-spaces, so that the first iteration of the loop 
 would print:

Team: Spurs, Score: 94

and the second iteration will produce:

Team: Suns, Score: 82

Does that help clarify the way split works?

Randy.

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



Re: Reading text file in reverse order

2004-03-12 Thread R. Joseph Newton
"John W. Krahn" wrote:

> [EMAIL PROTECTED] wrote:
> >
> > I have a text file with 5 or more lines as in:
> >
> > My name is this and that
> > I live in Denver Colorado
> > I live in washington
> > I live in Denver Virginia
> >
> > I am trying to read this file and print each line and each word in reverse order 
> > as in:
> >
> > ainigriv revned ni evil I (the output starts with the last last of the file and 
> > reverse each work as well).
> > Here is what I have done, but does not work:
> >
> > print "Enter a file name:\n";
> > my $file = ;
> > open (REGFILE, "$file") or die ("Cannot open file: $file: $!");
> >
> > while(my @line = ) {
> >
> > foreach my $lin(@line){
> > my @lines = $lin;
> > print reverse(@lines);
> > }
> > }
>
> use File::ReadBackwards;
>
> tie *FILE, 'File::ReadBackwards', $file
> or die "Cannot open $file: $!";
>
> while (  ) {
> chomp;
> print scalar reverse, "\n";
> }
>
> __END__

Looks cool, and perfectly tailored to the task.  How is it for handligg muti-charcter 
newlines?

Joseph


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




Re: help with a regex and greediness

2004-03-12 Thread Paul Johnson

Stuart White said:

> I'm not sure what's going wrong here.  Can someone
> tell me how I can split 'Spurs 94, Suns 82' into:
> array[0] == 'Spurs' and array[1] == 'Suns'

@array = /([[:alpha:]]+)/g;

-- 
Paul Johnson - [EMAIL PROTECTED]
http://www.pjcj.net


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




Re: help with a regex and greediness

2004-03-12 Thread Stuart White
I like the idea of using split() but decided to keep
most of my regex and incorporate split on the string.
So the string: 'Spurs 94, Suns 82' <-and there may or
may not be a space after the 2.
I decided to read up on split(), and then try to split
it.
This is what I came up with:

@teamscores = split(m#\s*\d*\,\s*#, $_);

This puts 'Spurs' in $teamscores[0] and 'Suns 82' in
$teamscores[1].

I think it has to do with the comma not being present
after 'Suns' so I modified the split() to look like
this:

@teamscores = split(m#\s*\d*\,*\s*#, $_);
that put 'p' in $teamscores[1]

so then I tried to make the comma and the space
optional as a group and did this:
@teamscores = split(m#\s*\d*(\,\s*)?#, $_);

and that gave me a use of uninitialized error with the
concatenation operator.  I'm not sure what that's
about.

i tried one more change:
@teamscores = split(m#\s*\d*\,?\s?#, $_);

Since the comma wasn't present in the second number,
and I wasn't sure if the space was either.  That
didn't give me what I expected.  it gave me:
$teamscores[0] == S and $teamscores[1] == p

I'm not sure what's going wrong here.  Can someone
tell me how I can split 'Spurs 94, Suns 82' into:
array[0] == 'Spurs' and array[1] == 'Suns'
Thanks. -stu




--- "Randy W. Sims" <[EMAIL PROTECTED]>
wrote:
> On 3/11/2004 9:01 PM, Stuart White wrote:
> 
> > I'm confused about greediness.
> > This is the line that I'm trying to match:
> > 
> > Spurs 94, Suns 82
> 
> If the line is as above, I probably wouldn't use a
> regex. The following 
> is more verbose, but easier to manage IMHO.
> 
> #!/usr/bin/perl
> 
> use strict;
> use warnings;
> 
> my $line = 'Spurs 94, Suns 82';
> 
> my (%scores);
> 
> my @teamscores = split(/\s*,\s*/, $line, 2);
> foreach my $teamscore (@teamscores) {
>$teamscore =~ s/^\s+//; $teamscore =~ s/\s+$//;
>my ($team, $score) = split(/\s+/, $teamscore, 2);
>$scores{$team} = $score;
> }
> 
> use Data::Dumper;
> print Dumper(\%scores);
> 
> 


__
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com

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




Re: Reading text file in reverse order

2004-03-12 Thread Mame Mbodji
Thank you so that. This is the kind of advice I have been expecting.
This is very helpful and I think I will be able to figure it out now. I
never intended for the group to do my HMW. I have been with this list
for over a year and I learned a lot, but I never posted a question
related to my homework.

"Randy W. Sims" wrote:
> 
> On 3/11/2004 11:05 PM, Mame Mbodji wrote:
> 
> > This is a hwk, but I never asked for a complete answer. I just needed
> > guidance because I was lost. Thank you anyway.
> 
> Did you understand the hint I gave earlier? Your code
> 
> while(my @line = ) {
>foreach my $lin(@line){
>  my @lines = $lin;
>  print reverse(@lines);
>}
> }
> 
> is equivelant to:
> 
> my @line = ;
> foreach my $lin(@line){
>my @lines = $lin;
>print reverse(@lines);
> }
> 
> because @line gets the whole file at one time, so the while loop only
> loops once. (put a print statement just after the while line to see for
> yourself.)
> 
> The variable @line should probably be named @lines (plural) because the
> array contains all lines in the file; each element in the array is a
> line in the file.
> 
> my @lines = ;
> 
> If you want the last line first and the first line last you'll need to
> reverse the elements in that array...
> 
> Next you'll need to iterate over each line and break up the string of
> characters into an array so you can reverse them. There are several ways
> to break a string into an array of characters (unpack,substr,split), but
> the common idiom in this case is to use split. The documentation for
> split will tell you exactly how to split the string into an array of
> characters.
> 
> Let us know if you need more hints.
> 
> --
> 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: Reading text file in reverse order

2004-03-12 Thread Mame Mbodji
Thanks for the advice, I will try HARDER and repost if I cannot figure
it out!

"R. Joseph Newton" wrote:
> 
> Mame Mbodji wrote:
> 
> > This is a hwk, but I never asked for a complete answer
> 
> 1.  The term "homework" refers to something fluid, rather than discrete, and
> therefore does not take an article ['a' or 'the']
> 2.  Please do not abbreviate words, unless the abbreviation is a very standard
> one.  I wasted 2-3 minutes just puzzling out what "hwk" meant: Hawk? some
> mispspelling or typographical error/  Who knows?  There are enough accidental
> errors that get into e-mail traffic.  There is no need to add those that arise
> simply from a lack of effort.
> 
> When asking for guidance related to school studies, it is a good idea to explain
> what topics you are covering.  The example problem you are working with can be
> handled in a number of ways.  Which one may be most appropriate depends largely
> on what programming tools it is intended to help you learn about.  Is the
> reverese function the focus of your studies?  Have shoft or unshift come up in
> your class readings?  Is the focus on handling string data?
> 
> One thing I would suggest from seeing your code--you need to have more respect
> for the material.
> Int his code:
> while(my @line = ) {
> 
> foreach my $lin(@line){
> my @lines = $lin;
> print reverse(@lines);
> }
> 
> }
> 
> You use some variant or abbreviation for the word line in three different
> places.  You do not use them sensibly.  The plural of line is lines.  This
> should probably be the name of the array, since it is the array that holds more
> than one line.  The elements in each line are characters, not lines.  Why do you
> call them @lines?   That doesn't make sense.
> 
> There are a number of simple ways to achieve the desired effect.  Please rework
> your code, using variable names that indicate that you have put some serious
> thought into the problem, and repost.  We can probably guide you towards some
> good solutions.
> 
> Joseph
-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 


Re: Reading text file in reverse order

2004-03-12 Thread John W. Krahn
[EMAIL PROTECTED] wrote:
> 
> I have a text file with 5 or more lines as in:
> 
> My name is this and that
> I live in Denver Colorado
> I live in washington
> I live in Denver Virginia
> 
> I am trying to read this file and print each line and each word in reverse order as 
> in:
> 
> ainigriv revned ni evil I (the output starts with the last last of the file and 
> reverse each work as well).
> Here is what I have done, but does not work:
> 
> print "Enter a file name:\n";
> my $file = ;
> open (REGFILE, "$file") or die ("Cannot open file: $file: $!");
> 
> while(my @line = ) {
> 
> foreach my $lin(@line){
> my @lines = $lin;
> print reverse(@lines);
> }
> }


use File::ReadBackwards;

tie *FILE, 'File::ReadBackwards', $file
or die "Cannot open $file: $!";

while (  ) {
chomp;
print scalar reverse, "\n";
}

__END__


John
-- 
use Perl;
program
fulfillment

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




Re: can somebody tell me what this means

2004-03-12 Thread sam lehman
On Thu, 11 Mar 2004 11:07:24 +0100, Ralf Schaa <[EMAIL PROTECTED]> 
wrote:

sam lehman wrote:

i got his code from a program i found, and i was wondering that the ? 
and the : are for?

$target = (@digits % 2) ? ($digits[int(@digits/2)]) : 
([EMAIL PROTECTED]/2-1]);

conditional statement (with lower priority than an 'if-construct' ?):

if (@digits % 2) {
   $target = ($digits[int(@digits/2)])
}else{
$target = ($digits[int(@digits/2)])
}
ahh, i see
thanks
so would:
something ? dosomething : somethingelse ? dosomethingelse : killyourself
be the same as
if (something){
dosomething
}
elsif (somethingelse){
dosomethingelse
}
else{
killyourself
}
???
--
http://www.backstab.net
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 



RE: Nucleotide Sequencing

2004-03-12 Thread Bill Akins
> -Original Message-
> From: Daniel T. Staal [mailto:[EMAIL PROTECTED] 
> Sent: Wednesday, March 10, 2004 8:11 PM
> To: Perl Beginners
> Cc: Sumit Kaur
> Subject: RE: Nucleotide Sequencing
> 
> 
> --As of Wednesday, March 10, 2004 6:29 PM -0600, Charles K. 
> Clarkson is 
> alleged to have said:
> 
> > Sumit Kaur <[EMAIL PROTECTED]> wrote:
> >:
> >: I am a fresh starter of Perl and I need to write a
> >: script that perform the same function done by the
> >: following JavaScript. I know it is wrong to ask for
> >: code but I am in urgent requirement of this.
> >
> >
> > Please state the nature of the emergency.
> 
> It can't be too urgent: He's asked the same question several 
> times in the 
> last two weeks.  He's also never responded to any answers, or 
> clarified the 
> question.
> 
> > BTW, http://bioperl.org/ has some excellent resources
> > for biologists.
> 
> He's been pointed there before.
> 
> At this point, this is a troll.
> 
> Daniel T. Staal
> 


Hmmm.  Maybe this should be forwarded to Dr. Peter Myler, Ph.D.
([EMAIL PROTECTED]).  Seems Sumit here is the good doctors
Bioinformatics Programmer, according to
http://sbri.org/research/myler_staff.asp  Maybe Doc can shed some light
on the real nature of the problem.  :)


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




Re: Reading text file in reverse order

2004-03-12 Thread R. Joseph Newton
Mame Mbodji wrote:

> This is a hwk, but I never asked for a complete answer

1.  The term "homework" refers to something fluid, rather than discrete, and
therefore does not take an article ['a' or 'the']
2.  Please do not abbreviate words, unless the abbreviation is a very standard
one.  I wasted 2-3 minutes just puzzling out what "hwk" meant: Hawk? some
mispspelling or typographical error/  Who knows?  There are enough accidental
errors that get into e-mail traffic.  There is no need to add those that arise
simply from a lack of effort.

When asking for guidance related to school studies, it is a good idea to explain
what topics you are covering.  The example problem you are working with can be
handled in a number of ways.  Which one may be most appropriate depends largely
on what programming tools it is intended to help you learn about.  Is the
reverese function the focus of your studies?  Have shoft or unshift come up in
your class readings?  Is the focus on handling string data?

One thing I would suggest from seeing your code--you need to have more respect
for the material.
Int his code:
while(my @line = ) {

foreach my $lin(@line){
my @lines = $lin;
print reverse(@lines);
}

}

You use some variant or abbreviation for the word line in three different
places.  You do not use them sensibly.  The plural of line is lines.  This
should probably be the name of the array, since it is the array that holds more
than one line.  The elements in each line are characters, not lines.  Why do you
call them @lines?   That doesn't make sense.

There are a number of simple ways to achieve the desired effect.  Please rework
your code, using variable names that indicate that you have put some serious
thought into the problem, and repost.  We can probably guide you towards some
good solutions.

Joseph



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