Re: hash problems

2003-12-13 Thread John W. Krahn
Jdavis wrote:
> 
> Hello,

Hello,

>  I have a script that gets items and corresponding price from a web
> site. all goes well until i put the item and price in a hash. When i try
> to print key and value from the hash it comes out all weired. Could some
> one take a look and see what im doing wrong.

Certainly.


> #! /usr/bin/perl -w

use strict;

> use LWP::Simple;
> 
> $item_string = '\<\!\-\- \#\#\# Display Item\'s Name and make a
> hyperlink \#\#\# \-\-\>';

You don't need to escape those characters, they are not special in
strings or regular expressions.

my $item_string = '';

And since you are using this as a regular expression you can compile it
here instead of later.

my $item_string = qr//;


> $price_string = 'color="red"';

my $price_string = qr/color="red"/;


> $URL = 'http://shop.altenergystore.com/items.asp?Cc=SP100%2D';
> $content = get($URL);
> 
> # put each line of $content into a array
> @content = split(/\n/, $content);
> 
> @content_reversed = reverse @content;
> 
> while(@content_reversed){
> $_ = pop(@content_reversed);
> if(/$item_string/){
>  $the_item = pop(@content_reversed);
>  ($trash,$clean_item) = split(/\/, $the_item);

You don't need a $trash variable, you can use undef instead or use a
list slice on the split results.  You don't need to backslash '<' or
'>'.

( undef, $clean_item ) = split //, $the_item;

Or:

$clean_item = (split //, $the_item)[1];


>  print "ITEM = $clean_item\n";
> 
>  do{
>$_ = pop(@content_reversed);
>  }until(/$price_string/); ## this is the price line

You don't need the do{} block as you only have a single statement.

  $_ = pop @content_reversed until /$price_string/; ## this
is the price line


>   ($trash,$ruff_price) = split(/\/,$_);
>   ($clean_price,$trash) = split(/\<\/font\>\<\/font\>/,$ruff_price);

$ruff_price = (split //)[1];
$clean_price = (split /<\/font><\/font>/, $ruff_price)[0];


>  print "PRICE = $clean_price\n";
>  $price_items{$clean_item} = $clean_price;
> }
> }
> 
> while(($k, $v) = each %price_items){
> print "K = $k";
> print "V = $v\n";
> }

Your problem is that $clean_item (your hash key) has a "\015" (CR)
character at the end.  When you print "K = $k" the carriage return moves
the cursor to the beginning of the line and "V = $v\n" prints over the
previous output.  The HTTP standard (RFC2616) defines CR LF as the
end-of-line marker and you are only removing the LF character.

A more simplified version of your code would be:

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

use LWP::Simple;

my $URL = 'http://shop.altenergystore.com/items.asp?Cc=SP100%2D';
my $content = get( $URL );

my %price_items = $content =~ m{
(?-x:)
.+?
(?i:)
\s* (\S.*?\S) \s* $
.+?
(?i-x:)
(\$\d[,.\d]+\d)
(?i:)
}smxg;

while ( my ( $k, $v ) = each %price_items ) {
print "K = $k  V = $v\n";
}

__END__



John
-- 
use Perl;
program
fulfillment

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




Getting the most recent file

2003-12-13 Thread Perl
I am trying to write some code to read the most recent log file in a
directory. I wrote some code below. This works but I was wondering if
there was a more efficient method to do this. Ideally I would like to
include hours, minutes and seconds but that's not necessary at this
point. 

--Paul 

foreach $iislog (@files){

($WRITETIME) = (stat("$iislogs\\$iislog"))[9];

print scalar localtime ($WRITETIME);

($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday,
$isdst) = localtime();
($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2,
$yday2, $isdst2) = localtime($WRITETIME);

if ($day == $day2 && $month == $month2) {



#print scalar localtime();
print "\n\n";
print "The file was last modified on: ";
print scalar localtime ($WRITETIME);
print "\n\n";

}
}


LDAPS and HTTPS not working with Unix

2003-12-13 Thread amol sarin
Hi
I have 2 problems which are as listed below:
1.In the first instance i have to check whether the
HTTPS service is running on a remote machine or
not.The following is the code snippet for it:

use LWP::UserAgent;

my ($strHttpURL)='https://machinename;
$ua = LWP::UserAgent->new;
$req = HTTP::Request->new(GET =>$strHttpURL);
$res = $ua->request($req);

if ($res->is_success) {
print ("$strHttpURL connected successfully");
return $TRUE;
}
else{
print "$strHttpURL not connected");
}

I have secured the https://machinename link. However,
the problem is though i am able to run the above code
from windows, it does not succeed in unix.Also, the
operation succeeds in unix when i try to access any
'http' service.
Is the problem related to some certificate mismatch.

2.The second problem is on teh similar lines,here i
have to check whether the LDAPS server is running or
not.In windows i am able to check both the LDP and
LDAPS services. However, in UNIX the LDAP code works
fine but LDAPS again is not able to connect
properly.The following is the code snippet for LDAPS:

use Net::LDAPS;
use Net::LDAP;


$ldaps = Net::LDAPS->new( $strLDAPIpAdd,port
=>$strLDAPPort,onerror=>undef);
if ($ldaps==undef) {
print("Ip Address of LDAP server over SSL is not
correct");
return $ERROR;
}

$mesg = $ldaps->bind();
if ($mesg->code==0) {
print ("LDAP over SSL with ip $strLDAPIpAdd connected
successfully!");
$mesg=$ldaps->unbind;
 }
 else{
 print("LDAP over SSL with ip $strLDAPIpAdd not
connected...");
$mesg=$ldaps->unbind;
}   

I think both the above problems are related.Pls help
Regds
A

__
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing.
http://photos.yahoo.com/

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




Re: Parentheses

2003-12-13 Thread Rob Dixon
R. Joseph Newton wrote:
>
> Rob Dixon wrote:
> >
> > Not sure which way you're leaning here. I never saw you as anti the 'it'
> > variable $_?
> >
> > Rob
>
> I think its a matter of context, Rob.

I agree 100%. But see later.

> What I cringe at is seeing a default
> variable being used in dense code.  The more other code happening, the less
> clear will be the meaning of $_.  When I first started using Perl, I just
> didn't like it a bit--it seemed just too damned tech-ish.  I've come to
> appreciate, though, that it can be very effective and actually aid clarity in
> a more staccato context.  I would say that it should be used only in contexts
> where it is very clear what it means:
>
> foreach (@lines) {
>chomp;
>s/dog/cat/g;
>my @words = split;
>$words[0] = lc $words[0];
>$_ = join ' ', reverse @words;
>print ucfirst $_, "\n";
> }
>
> While the purpose of the above may bve totally incomprehesible, there is no
> question about what $_ is.  <;:-o)

One proviso here. I always feel very uncomfortable about explicitly assigning
to $_. As I implied in my post to Wiggins, $_ is very much the equivalent to
'it', and I would no more use 'it' over more than a simple English sentence
than I would use $_ across nested loops, procedure calls or whatever. In English
your lines above say

  For each element of @lines, chomp it, substitute 'cat' for 'dog' in it, split it
  into @words...

and there the simile starts to fall down because of the explicit assignment. That's
why I prefer the idiom:

  for (join ' ', reverse @words) {
print ucfirst $_, "\n";
  }

(No I'd never write this code, but the circumstance is artificial.)

This starts a new 'sentence' saying

  With the value obtained by joining the elements of the reversed @words array with
  a space character, print it followed by a newline and with its first letter 
uppercased.

I believe that the reason all this makes sense to me in this way is because of
Larry's linguistic background. Some will love it and some hate it: something like the
difference between a bricklayer and a sculptor.

As a final thought, I would point out that $_ is a package ('our') variable, but is
localised by 'map', 'grep', 'foreach (LIST)' and 'while (<>)'. The only worry, then,
is subroutine calls which can easily do

  local $_;

if that's what you want.


Rob



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




Re: Getting the most recent file

2003-12-13 Thread Rob Dixon
<[EMAIL PROTECTED]> wrote:
>
> I am trying to write some code to read the most recent log file in a
> directory. I wrote some code below. This works but I was wondering if
> there was a more efficient method to do this. Ideally I would like to
> include hours, minutes and seconds but that's not necessary at this
> point.
>
> foreach $iislog (@files) {
>
>   ($WRITETIME) = (stat("$iislogs\\$iislog"))[9];
>
>   print scalar localtime ($WRITETIME);
>
>   ($seconds, $minutes, $hours, $day, $month, $year, $wday, $yday, $isdst) = 
> localtime();
>   ($seconds2, $minutes2, $hours2, $day2, $month2, $year2, $wday2, $yday2, $isdst2) = 
> localtime($WRITETIME);
>
>   if ($day == $day2 && $month == $month2) {
>
> print "\n\n";
> print "The file was last modified on: ";
> print scalar localtime ($WRITETIME);
> print "\n\n";
>   }
> }

Hi Paul.

First of all,

  use strict;   # And declare all of your variables
  use warnings;

# And indent your code!

Then I'm not sure what you need. You say you want to read the most recent log file,
but your code just prints out a list of modification times. Do you need this
as well,or do you just want to find the latest file?

  (stat $file)[9]

gives you the modification date, while

  -M $file

gives you the age of the file. So you could just write

  @files = sort { -M $a <=> -M $b } @files;
  print $files[-1], "\n";

Or do you need anything more?

HTH,

Rob



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




Re: LDAPS and HTTPS not working with Unix

2003-12-13 Thread Peter Scott
Make sure you have Crypt::SSLeay installed.

-- 
Peter Scott
http://www.perldebugged.com/
*** NEW *** http//www.perlmedic.com/

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




Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread Jerry Rocteur
Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Anyway, enough whining, now I've going through code that is working and 
thought I'd see the big difference if I change it to use warnings and 
strict and this little routing gives me  'Use of uninitialized value in 
pattern match (m//) at ./getopt.pl line 14.'

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

#if ($#ARGV >= 0) { # What I've tried
while ($_ = $ARGV[0], /^-/) {
shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
else { print "$_ unknown option\n";
Usage;
}
}
#}
Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

Jerry

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



Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread Wiggins d'Anconia
Jerry Rocteur wrote:
Hi,

I'm trying to be a good boy and use strict and warnings ..

The more I do, the more I feel I'm wasting so much time and should 
become productive, my code looks full of 'my', I could understand the 
requirement inside a sub routing but in the main code it gives me the 
willies. My DBI Perl is even more of a headache ;-((

Right now you probably are.  In the future the loads of time it saves 
will repay you greatly.  Stick with it, it will help... this comes from 
someone that switched "cold turkey" from not using them to using them 
after coding in Perl for 3+ years...

Anyway, enough whining, now I've going through code that is working and 
thought I'd see the big difference if I change it to use warnings and 
strict and this little routing gives me  'Use of uninitialized value in 
pattern match (m//) at ./getopt.pl line 14.'

The above is just a warning so your code is running, granted it doesn't 
do much...

Line 14 is the while line..

I've tried all sorts of stuff with defined but keep getting syntax 
errors. I've tried perldoc warnings and perldoc perllexwarn .. In any 
case, unless I'm really missing something, I can't see what could be 
problematic with the while statement below, of course this shows my 
ignorance but as I've decided to use warnings and strict, I want to do 
it right..

How would a pedant code the following to avoid this warning.. Your 
answers will help me in the future.

They wouldn't. They would use Getopt::Std or Getopt::Long...

perldoc Getopt::Std
perldoc Getopt::Long
Now

#if ($#ARGV >= 0) { # What I've tried
To test if an array has length simply take it in scalar context,

if (@ARGV) {

while ($_ = $ARGV[0], /^-/) {
I believe the issue is that the $_ is not set by the time you hit the 
pattern match, there is probably a way to make it, but to me it is 
simpler to just add a line after the initial test such as:

next unless (/^-/);

Inside the loop and drop the test inside the conditional.

shift;
last if /^--$/;
if (/^-d(.*)/) { $debug++ }
elsif (/^-v(.*)/) { $verbose++ }
I assume that $debug and $verbose have been pre-declared and that you 
have Usage prototyped or something, as it is a bare word...

else { print "$_ unknown option\n";
Usage;
}
}
More code showing specifically why I have been rambling about $_ in the 
last couple of days.  If you are going to shift off the argument list 
why not just do it in the while loop when you are setting $_?  And Perl 
is very nice and lets you leave the semi-colons off in the above, to me 
it is a bad style to get into and will likely lead to errors later when 
you (or someone else) decides to add additional statements to those 
blocks.  While you are a beginner code *exactly* what you mean, use lots 
of names, avoid the shortcuts, later when you don't need to ask these 
kinds of questions, then sign up for a golf tournament...

#}

Thanks in advance, I really want to put, Perl with warnings and strict 
in my CV ;-

I have wondered about this for a while, putting that you use warnings 
and strict into a CV is a tough choice, to me I wouldn't likely talk to 
a candidate unless they used them, but I am not sure I would put them on 
a CV because to an advanced person it would seem overally obvious. 
Though I think it is something good to bring up in an interview, and I 
have had several interviewers ask about them... what does the group 
think (about including it in a CV)? (Obviously I know what the thoughts 
are about including them in the code)And naturally code samples 
would reflect their use.

I would also check out:

perldoc Pod::Usage

http://danconia.org

A decent template, any gurus have improvements?

UNTESTED---

#!/usr/local/bin/perl
use strict;
use warnings;
use Getopt::Long;
use Pod::Usage;
pod2usage("No options specified\n") unless (@ARGV);



# configure GetOptions with some standard gnu options
my $opt_parser = new Getopt::Long::Parser ('config' => 
['gnu_compat','bundling','permute','no_getopt_compat'] );

# init configuration
my $cmdopts = {};
# get configuration
$opt_parser->getoptions($cmdopts,
'help|h',
'debug|d',
'verbose|v',
) or pod2usage(2);
# print the help message if they asked just for it
pod2usage(1) if (defined($cmdopts->{'help'}));
if ($cmdopts->{'verbose'}) {
print "Verbose Mode\n";
}
if ($cmdopts->{'debug'}) {
print "Debugging Mode\n";
}


#
__END__
=head1 NAME

getopt - A program for parsing command line arguments

=head1 SYNOPSIS

getopt [options]

 Options:
   --debug  turn on debugging
   --verboseturn on verbosity
   --help   print this message
=head1 OPTIONS

=over 8

=item B<--debug>

Mode of

Re: IP question

2003-12-13 Thread drieux
On Dec 12, 2003, at 4:13 PM, Michael Sullivan wrote:

Michael,

I'm routing this back to the list so that more can share in it.

The gateway IP address for my domain is 68.15.193.18, so could I say:
when you say 'gateway IP address' is this like
the address you are issued from an ISP? Hence
your WAN side address???
$rem_addr = $ENV{REMOTE_ADDR};
if (rem_addr == '68.15.193.168')
{
#Do nothing
}
else
{   
#Add to count
}
Would that work?
not the way you would expect - you're trying to
do a numeric compare with between two strings.
One of the cool 'reserved words' in Perl is
"unless" that functions as 'if not $condition'
so you might go with say
	$count++ unless ( $rem_addr eq '68.15.193.168');

But I would probably be doing the compare in a
sub so would probably have it as
	$count++ unless is_local_host_to_our_domain();

and then down in

sub is_local_host_to_our_domain
{
# fail early if there is no $ENV{REMOTE_ADDR}
return(0) unless defined($ENV{REMOTE_ADDR});
$rem_addr = $ENV{REMOTE_ADDR};
# solve if this is actually inside our domain

$retval;
}
in perl you can get away with just 'asserting' the value
as the last element of a 'sub' rather than
		return($retval);

I don't know much about Perl, but if it were C++ it would require some
kind of data type, and I don't know what data type an IP address would
be.  I'd call it a string...
Perl is promiscuous that way.



ciao
drieux
---

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



Re: Parentheses

2003-12-13 Thread Wiggins d'Anconia
Rob Dixon wrote:
R. Joseph Newton wrote:

Rob Dixon wrote:

Not sure which way you're leaning here. I never saw you as anti the 'it'
variable $_?
Rob
I think its a matter of context, Rob.


I agree 100%. But see later.


What I cringe at is seeing a default
variable being used in dense code.  The more other code happening, the less
clear will be the meaning of $_.  When I first started using Perl, I just
didn't like it a bit--it seemed just too damned tech-ish.  I've come to
appreciate, though, that it can be very effective and actually aid clarity in
a more staccato context.  I would say that it should be used only in contexts
where it is very clear what it means:
Yeh I definitely agree, which was my comment about one liners. If your 
program is 10 lines long and is only likely ever to grow to 15 then by 
all means, or if it will never even end up in a file, then sure. But you 
breach a certain point and all of a sudden "it" is on shaky ground...

foreach (@lines) {
  chomp;
  s/dog/cat/g;
  my @words = split;
  $words[0] = lc $words[0];
  $_ = join ' ', reverse @words;
  print ucfirst $_, "\n";
}
While the purpose of the above may bve totally incomprehesible, there is no
question about what $_ is.  <;:-o)


One proviso here. I always feel very uncomfortable about explicitly assigning
to $_. As I implied in my post to Wiggins, $_ is very much the equivalent to
'it', and I would no more use 'it' over more than a simple English sentence
than I would use $_ across nested loops, procedure calls or whatever. In English
your lines above say
  For each element of @lines, chomp it, substitute 'cat' for 'dog' in it, split it
  into @words...
I didn't pick up on what you meant by your "explicit" 'it'... This is an 
excellent explanation and demonstration of why I don't like it, even 
though I couldn't have provided *it*!

and there the simile starts to fall down because of the explicit assignment. That's
why I prefer the idiom:
  for (join ' ', reverse @words) {
print ucfirst $_, "\n";
  }
(No I'd never write this code, but the circumstance is artificial.)

This starts a new 'sentence' saying

  With the value obtained by joining the elements of the reversed @words array with
  a space character, print it followed by a newline and with its first letter 
uppercased.
I believe that the reason all this makes sense to me in this way is because of
Larry's linguistic background. Some will love it and some hate it: something like the
difference between a bricklayer and a sculptor.
Sounds like good reasoning to me.  Though Americans' grasp of the 
English language is going downhill so fast that who knows what we will 
end up with next. It goed to the it and it did some iting to the 
thingamait, and it was smurfy!  I won't get into a rant about why the 
media should be outlawed from putting ex-professional athletes on the 
air, especially live!

As a final thought, I would point out that $_ is a package ('our') variable, but is
localised by 'map', 'grep', 'foreach (LIST)' and 'while (<>)'. The only worry, then,
is subroutine calls which can easily do
  local $_;

if that's what you want.

Let's not and say we did

http://danconia.org

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



Re: Move a file

2003-12-13 Thread Wiggins d'Anconia
Rob Dixon wrote:
Wiggins D Anconia wrote:



Depending on what is writing the files, aka another controllable
program? I have had good luck with writing the file to a temporary
location, usually with a dot on the front, then executing a move from
that temp location to the real name. A move is usually a single action
(at least that's my understanding) and for most filesystems is merely a
single inode update.  Then just have the directory watcher skip dot
files... Though the lock would probably be better...


Hi Wiggins.

Yes, that will often work, depending on the filing system. But a 'move'
will usually do 'copy' followed by 'delete'. 
What filesystems act in that matter? I believe you that there are ones 
that do it that way, none of the Unix variants that I have experienced 
do (or seem to).  Unless we are talking about 'mv' as opposed to 
'rename' which I should have been more explicit about.  A rename merely 
moves the starting inode, assuming the file is staying on the same 
partition, which in this case if the temporary file is written into the 
same directory then it is...

Occasionally you can move
a file while it is being written to, as the application doing the writing
doesn't care where it appears in the directory structure. But that's
unusual. It's more common that the 'copy' will be allowed to grab an
image of the data flushed so far and the subsequent 'delete' will
be executed once the writing app has closed the original file.
Without extensive knowledge of the platform and filing system I don't
think it's safe to assume anything!
Right which is why the locking is better. However, in many cases one 
will be familar enough with the system where the code is deployed, so 
this method is just shorter (to code).

http://danconia.org

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



Re: Invoking multiple analyses

2003-12-13 Thread Wiggins d'Anconia
Amit Phatak wrote:
I am currently invoking an ABAQUS (A finite element analysis package) analysis through perl using the command - 

system("/usr/local/bin/tcsh -c 'source /eng/local/lib/source/use -quiet
abaqus; /eng/tools/abaqus/6.3/Commands/abaqus job=$input_file'");
where $input_file has a name like 'file.inp'

This analysis takes around 1 minute to complete until which i stall the script using sleep(60).

I now wish to invoke 3 such analyses at the same time on different $input_file files.

Kindly give your suggestions.

'system' by its nature blocks.  Generally this is avoidable with a 
fork/exec model.  You may want to have a look through

perldoc perlipc

Or read through the archives for the last couple of weeks where there 
was some discussion of using multiple simultaneous forks...

http://danconia.org

POE (there, I did it again)

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



Re: Newbie question

2003-12-13 Thread Randal L. Schwartz
> "Michael" == Michael Sullivan <[EMAIL PROTECTED]> writes:

Michael> Can anyone recommend any free Perl tutorials?  I know almost nothing
Michael> about what I'm doing, only that it looks somewhat like C++...

Once you have the basics down, there are 198+ articles at
www.stonehenge.com/merlyn/columns.html that can enhance your knowledge.

-- 
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: help looping through text file

2003-12-13 Thread Joel Newkirk
On Fri, 2003-12-12 at 15:59, John Fitzgerald wrote:
> I need a list set like this:
> IDdate
> 3008 11/1/03  
> 3008 11/1/03  
> 3008 11/1/03  
> 3010 12/1/03
> 3010 12/1/03
> 
> So I need repeating ID's, with the earliest date for
> each ID. If the order of the data is preserved, I can
> use just those two columns for processing, then
> combine them back with the other columns afterward.

Warning - I've only been working in Perl for just over a week... ;^)

If I understand the unwritten goal correctly, you want to actually
modify the data? Either in the original file or a new file with the
changed dates? Why should it matter if the order is preserved while
processing, as long as the order is preserved in the result?  That also
implies retaining all the data read in during the 'first pass', which
isn't necessary as you can match up IDs trivially.  Largely influenced
by my single 'real' Perl project, (involving multiple 100mb+ logfiles) I
tend to work with the minimum amount of data at a time that is
reasonable.

I would approach it like this:

Loop over the data file once, creating a hash with the IDs as keys and
the earliest date found as the value for each key.  Loop over the data
file a second time and instead of the date field from the file, use the
date field value retrieved from the hash, and write to a file or format
for screen presentation or whatever your goal is for this data.

I'm a rank beginner with Perl, so the following quite likely contains at
least one error, but I'd write it something like this:

my @clientbirth;

open INFILE, "sourcefile" or die "sourcefile open failed - $!";
while ()
{
my ($uid, $birth, undef) = split;
$clientbirth{$uid} = earlierdate($birth,$clientbirth{$uid});
}
close INFILE;

open INFILE, "sourcefile" or die "sourcefile open failed - $!";
open OUTFILE, ">destfile" or die "destfile open failed - $!";
while ()
{
my ($uid, undef, @data) = split;
print OUTFILE, $uid, $clientbirth{$uid}, @data;
}
close OUTFILE;
close INFILE;


With an implicit sub earlierdate() that returns the earlier of the two
dates presented to it, dealing with whatever the date format is. 
Obviously if this all takes place in sequence it's not necessary to
close and reopen INFILE, just rewind the file to the start, like "seek
(INFILE,0,0);".  Just as obviously, if you aren't intending to write the
data out to file, the second half is inappropriate... ;^)  And there's
an implied assumption that sourcefile's contents aren't subject to
change while being processed.

There are ways to accomplish it in a single pass as well, although
unless you're assured that the 'earliest date' is also the first one to
appear for a given ID, it gets complicated pretty quickly unless you
simply read all data in and then work with it.  (Your sample data shows
out-of-order dates, IE for ID=3010.)

j

> --- Rob Dixon <[EMAIL PROTECTED]> wrote:
> > John Fitzgerald wrote:
> > >
> > > Hi, I'm fairly new to Perl, and trying to do a
> > simple
> > > operation on a text file exported from excel.
> > > ID  Enrolled Extraneous Columns
> > > 3008 05-Aug-03
> > > 3008 05-Aug-03
> > > 3008 05-Aug-03
> > > 3008 05-Aug-03
> > > 3008 24-Sep-03
> > > 3009 11-Aug-03
> > > 3010 19-Nov-03
> > > 3010 11-Jul-03
> > > 3010 11-Jul-03
> > > 3010 11-Jul-03
> > > 3011 15-Jul-03
> > >
> > > As you can see, the dates for a given ID are
> > > different. What I need to do, is set the dates all
> > to
> > > the earliest date for that ID (client-birth date).

> > The
> > > other columns are are important, but don't factor
> > in
> > > here.

-- 
"Not all those who wander are lost."  - JRR Tolkien


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




Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread Rob Dixon
Jerry Rocteur wrote:
>
> I'm trying to be a good boy and use strict and warnings ..

Well done!

> The more I do, the more I feel I'm wasting so much time and should
> become productive, my code looks full of 'my', I could understand the
> requirement inside a sub routing but in the main code it gives me the
> willies. My DBI Perl is even more of a headache ;-((

Your problem is more than likely because you're expecting Perl to be
like another language. The usual ones are C and shell script. Perl's
syntax is often quite like C's, and the built-in functions are a fair
match, but unless you're used to declaring variables locally to their
scope of use as in C++ you will end up with a long preamble declaring
everything, which can be less than useful.

> Anyway, enough whining, now I've going through code that is working and
> thought I'd see the big difference if I change it to use warnings and
> strict and this little routing gives me  'Use of uninitialized value in
> pattern match (m//) at ./getopt.pl line 14.'
>
> Line 14 is the while line..

'use warnings' will moan at you if a variable's value is 'undefined'.
It's left this way straight after either

  my $var

or

  $var = undef

If you define stuff like:

  my $var = 0

then you won't get this problem. But don't go around initialising
all variables in their declarations. It's just a warning and is useful
as such, and anyway Perl will let you concatenate or increment an
undefined value. i.e.

  my $var;

followed by
  $var++;
or
  $var .= '>>'

will work fine without any warnings.

> I've tried all sorts of stuff with defined but keep getting syntax
> errors. I've tried perldoc warnings and perldoc perllexwarn .. In any
> case, unless I'm really missing something, I can't see what could be
> problematic with the while statement below, of course this shows my
> ignorance but as I've decided to use warnings and strict, I want to do
> it right..
>
> How would a pedant code the following to avoid this warning.. Your
> answers will help me in the future.

You need to get to understand Perl idioms. I've started by reducing your
indents from 8 chars to 2 because that makes it more visible for me.

> if ($#ARGV >= 0) {

This says 'if the index of the last array element is zero or more'.
You don't mean that, because an array with a single element will
have a last element with an index of zero. Try

  if (@ARGV) {
:
  }

>   while ($_ = $ARGV[0], /^-/) {
>
> shift;

OK, these lines together pull the next argument from @ARGV and
quit the loop unless it begins with a hyphen. The reason you're
getting a warning is that once your 'shift' statement below has
finally emptied the array, $_ = $ARGV[0] will set $_ to 'undef'
so the pattern match is comparing against an undefined value.

This does the same:

  foreach (@ARGV) {

last unless /^-/;

except that the parameters are left in @ARGV instead of being
shifted off, and the loop is executed just once for each
element of @ARGV.

> last if /^--$/;

Break out if the element is just two hyphens. That's fine.

> if (/^-d(.*)/) {
>   $debug++
> }

Again, that'll do. But unless you need to capture whatever follows
the '-d' then you want just

 if (/^-d/) {
   $debug++
 }

> elsif (/^-v(.*)/) {
>   $verbose++
> }

Same here:

  elsif (/^-v/) {
$verbose++
  }

> else {
>   print "$_ unknown option\n";
>   Usage;
> }
>   }
> }

And the rest's OK. But I'd write it something like this. (Actually I would
probably never write this, but my code depends on the context of the
code and what exactly you need to do with the results :)

  foreach (@ARGV) {

next unless /^-/;

last if $_ eq '--';

if ( /^-(d|v)/ ) {
  $debug++ if $1 eq 'd';
  $verbose++ if $1 eq 'v';
}
else {
  print "$_ unknown option\n";
  Usage;
}
  }

HTH,

Rob



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




Re: could use an audit

2003-12-13 Thread Rob Dixon
James Edward Gray II wrote:
>
> On Dec 12, 2003, at 6:20 PM, Kenton Brede wrote:
>
> > I've cobbled some code together that will allow me to parse a file
> > snarfing 4 lines which consist of server name and Daily output of
> > bandwith usage.  I've pasted an example of what I have at the bottom of
> > this mail.  If anyone would like to take the time to show me how it
> > should really be done I would apreciate it.  I'm not exactly a
> > programming wonder and trying to learn.
>
> First, just let me say that you've done very well.  You use strict and
> warnings, your code works and you want to know how to make it better.
> I can't ask for much more than that!  :)

[snip stuff]

I couldn't have put it better James. Well done.

Rob



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




Re: could use an audit

2003-12-13 Thread John W. Krahn
Kenton Brede wrote:
> 
> I've cobbled some code together that will allow me to parse a file
> snarfing 4 lines which consist of server name and Daily output of
> bandwith usage.  I've pasted an example of what I have at the bottom of
> this mail.  If anyone would like to take the time to show me how it
> should really be done I would apreciate it.  I'm not exactly a
> programming wonder and trying to learn.

James covered a lot of good points so I won't go over them again.  When
I see groups of input lines I usually think: "Can I modify the Input
Record Separator to capture the whole group?"  If you can do that then
you can use a while loop to read one group at a time and not have to
slurp the entire file to process it.


#!/usr/bin/perl
use warnings;
use strict;

$/ = "\n* ";
while (  ) {
next unless /Daily/;
chomp;
s/\A(.+?)^//sm and my $name = $1;
s/\A.+(?=^.*?Daily)//sm;
print "* $name$_";
}

__DATA__

* Leo

# Bandwidth Usage
eth0 Total for 106.95 days:
RX 307.28 MB
TX 768.05 MB
eth0 Daily average:
RX 2.87 MB
TX 7.18 MB

* Buffy2

# Bandwidth Usage
eth0 Total for 14.70 days:
RX 141.28 MB
TX 2.03 MB
eth0 Daily average:
RX 9.61 MB
TX 0.14 MB



John
-- 
use Perl;
program
fulfillment

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




Re: hash problems

2003-12-13 Thread jdavis
On Fri, 2003-12-12 at 23:58, John W. Krahn wrote:
> Jdavis wrote:
> > 
> > Hello,
> 
> Hello,
> 
> >  I have a script that gets items and corresponding price from a web
> > site. all goes well until i put the item and price in a hash. When i try
> > to print key and value from the hash it comes out all weired. Could some
> > one take a look and see what im doing wrong.
> 
> Certainly.
> 
> 
> > #! /usr/bin/perl -w
> 
> use strict;
> 
> > use LWP::Simple;
> > 
> > $item_string = '\<\!\-\- \#\#\# Display Item\'s Name and make a
> > hyperlink \#\#\# \-\-\>';
> 
> You don't need to escape those characters, they are not special in
> strings or regular expressions.
> 
> my $item_string = '';
> 
> And since you are using this as a regular expression you can compile it
> here instead of later.
> 
> my $item_string = qr//;
> 
> 
> > $price_string = 'color="red"';
> 
> my $price_string = qr/color="red"/;
> 
> 
> > $URL = 'http://shop.altenergystore.com/items.asp?Cc=SP100%2D';
> > $content = get($URL);
> > 
> > # put each line of $content into a array
> > @content = split(/\n/, $content);
> > 
> > @content_reversed = reverse @content;
> > 
> > while(@content_reversed){
> > $_ = pop(@content_reversed);
> > if(/$item_string/){
> >  $the_item = pop(@content_reversed);
> >  ($trash,$clean_item) = split(/\/, $the_item);
> 
> You don't need a $trash variable, you can use undef instead or use a
> list slice on the split results.  You don't need to backslash '<' or
> '>'.
> 
> ( undef, $clean_item ) = split //, $the_item;
> 
> Or:
> 
> $clean_item = (split //, $the_item)[1];
> 
> 
> >  print "ITEM = $clean_item\n";
> > 
> >  do{
> >$_ = pop(@content_reversed);
> >  }until(/$price_string/); ## this is the price line
> 
> You don't need the do{} block as you only have a single statement.
> 
>   $_ = pop @content_reversed until /$price_string/; ## this
> is the price line
> 
> 
> >   ($trash,$ruff_price) = split(/\/,$_);
> >   ($clean_price,$trash) = split(/\<\/font\>\<\/font\>/,$ruff_price);
> 
> $ruff_price = (split //)[1];
> $clean_price = (split /<\/font><\/font>/, $ruff_price)[0];
> 
> 
> >  print "PRICE = $clean_price\n";
> >  $price_items{$clean_item} = $clean_price;
> > }
> > }
> > 
> > while(($k, $v) = each %price_items){
> > print "K = $k";
> > print "V = $v\n";
> > }
> 
> Your problem is that $clean_item (your hash key) has a "\015" (CR)
> character at the end.  When you print "K = $k" the carriage return moves
> the cursor to the beginning of the line and "V = $v\n" prints over the
> previous output.  The HTTP standard (RFC2616) defines CR LF as the
> end-of-line marker and you are only removing the LF character.
> 
> A more simplified version of your code would be:
> 
> #! /usr/bin/perl -w
> use strict;
> 
> use LWP::Simple;
> 
> my $URL = 'http://shop.altenergystore.com/items.asp?Cc=SP100%2D';
> my $content = get( $URL );
> 
> my %price_items = $content =~ m{
> (?-x:)
> .+?
> (?i:)
> \s* (\S.*?\S) \s* $
> .+?
> (?i-x:)
> (\$\d[,.\d]+\d)
> (?i:)
> }smxg;
> 
> while ( my ( $k, $v ) = each %price_items ) {
> print "K = $k  V = $v\n";
> }
> 
> __END__
> 
> 
> 
> John
> -- 
> use Perl;
> program
> fulfillment

thanks all those who replied. I appreciate the help :)
I will look into use Strict.

thanks again,
-- 
jdavis <[EMAIL PROTECTED]>


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




Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread R. Joseph Newton
Wiggins d'Anconia wrote:

> More code showing specifically why I have been rambling about $_ in the
> last couple of days.  If you are going to shift off the argument list
> why not just do it in the while loop when you are setting $_?

Thanks, Wiggins, and keep on rambling.  The point needs reiteration.  Aside from
the needle-in-a-haystack problems, I'd say that it's a good rule of thumb:

If you have to specifically assign $_, don't bother.  Perl already assigns it in
the contexts in which it is appropriate

> And Perl
> is very nice and lets you leave the semi-colons off in the above, to me
> it is a bad style to get into and will likely lead to errors later when
> you (or someone else) decides to add additional statements to those
> blocks.  While you are a beginner code *exactly* what you mean, use lots
> of names, avoid the shortcuts, later when you don't need to ask these
> kinds of questions, then sign up for a golf tournament...

Yes and yes.

>
>
> > #}
> >
> > Thanks in advance, I really want to put, Perl with warnings and strict
> > in my CV ;-
> >
>
> I have wondered about this for a while, putting that you use warnings
> and strict into a CV is a tough choice, to me I wouldn't likely talk to
> a candidate unless they used them, but I am not sure I would put them on
> a CV because to an advanced person it would seem overally obvious.
> Though I think it is something good to bring up in an interview, and I
> have had several interviewers ask about them... what does the group
> think (about including it in a CV)? (Obviously I know what the thoughts
> are about including them in the code)And naturally code samples
> would reflect their use.
>

I think about the only place it would be appropriate is in notes describing
coding samples available for interview or included.  If sufficiently understated,
it may reassure an interviewer or screener that they are not wasting time:

Codes samples included  [all compiled using strict compilation option and
pre-tested]

Which at least indicates to the reader that they are looking at something which
has run successfully.  Definitely not something to wave a big flag over,
though--it would be like listing:
Have mastered ABCs
...at the top of a resume for an English professorship.

Joseph


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




Re: help looping through text file

2003-12-13 Thread John W. Krahn
John Fitzgerald wrote:
> 
> Hi,

Hello,

> I'm fairly new to Perl, and trying to do a simple
> operation on a text file exported from excel.
> ID  Enrolled Extraneous Columns
> 300805-Aug-03
> 300805-Aug-03
> 300805-Aug-03
> 300805-Aug-03
> 300824-Sep-03
> 300911-Aug-03
> 301019-Nov-03
> 301011-Jul-03
> 301011-Jul-03
> 301011-Jul-03
> 301115-Jul-03
> As you can see, the dates for a given ID are
> different. What I need to do, is set the dates all to
> the earliest date for that ID (client-birth date). The
> other columns are are important, but don't factor in
> here. I'd appreciate any help. Thanks -John

In order to compare the dates you need to rearrange the fields to a more
comparable format like MMDD.

my %mons = qw(
Jan 01 Feb 02 Mar 03 Apr 04 May 05 Jun 06
Jul 07 Aug 08 Sep 09 Oct 10 Nov 11 Dec 12
);
my $mons = join '|', keys %mons;

# convert dd-Mmm-yy to mmdd 
sub conv_date {
my ( $day, $mon, $yr ) = @_;
# convert '51' to '1951' and '50' to '2050'
# adjust to taste
$yr = ( $yr > 50 ? 19 : 20 ) . $yr;
return "$yr$mons{$mon}$day";
}

my ( %record, $id );
while (  ) {
( $id, my ( $old_date, @date ) ) =
/^(\d+)\s+((\d+)-($mons)-(\d+))/
or do { print; next };
if ( not exists $record{ $id } or eof DATA ) {
for my $key ( keys %record ) {
for my $line ( @{ $record{ $key }{ lines } } ) {
$line =~ s/\d+-(?:$mons)-\d+/$record{$key}{date}/;
print $line;
}
}
%record = (
$id => {
date  => $old_date,
comp  => conv_date( @date ),
lines => [ $_ ],
}
);
}
else {
my $comp = conv_date @date;
if ( $comp lt $record{ $id }{ comp } ) {
$record{ $id }{ comp } = $comp;
$record{ $id }{ date } = $old_date;
}
push @{ $record{ $id }{ lines } }, $_;
}
}

__DATA__
ID  Enrolled Extraneous Columns
300805-Aug-03Extraneous Columns
300805-Aug-03Extraneous Columns
300805-Aug-03Extraneous Columns
300805-Aug-03Extraneous Columns
300824-Sep-03Extraneous Columns
300911-Aug-03Extraneous Columns
301019-Nov-03Extraneous Columns
301011-Jul-03Extraneous Columns
301011-Jul-03Extraneous Columns
301011-Jul-03Extraneous Columns
301115-Jul-03Extraneous Columns



John
-- 
use Perl;
program
fulfillment

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




Re: Parentheses

2003-12-13 Thread R. Joseph Newton
Rob Dixon wrote:

> > foreach (@lines) {

#  too many lines here

> > }
> >
> > While the purpose of the above may bve totally incomprehesible, there is no
> > question about what $_ is.  <;:-o)
>
> One proviso here. I always feel very uncomfortable about explicitly assigning
> to $_. As I implied in my post to Wiggins, $_ is very much the equivalent to
> 'it', and I would no more use 'it' over more than a simple English sentence
> than I would use $_ across nested loops, procedure calls or whatever. In English
> your lines above say

You're right.  I actually got carried away.  I was having so much fun coming up with 
the most
pointless code possible. that I forgot the main point.  The use of the idefault $_ did 
serve
its purpose, though, perverse as it was.  I should probably have done the print 
outside the
loop to demonstrate both the purpose and danger of using "it":

my @lines = ();

foreach (@lines) {
   chomp;
   s/dog/cat/g;
   my @words = split;
   $words[0] = lc $words[0];
   $_ = join ' ', reverse @words;
}

print"$_\n" for @lines;
#same data, results as previous sample

...has the same effect as printing from inside the loop.  Which means that my array 
contents
have either been effectively modified, or totally hashed, depending on whether that 
was the
desired effect.

FWIW, on the fairly rare occasions that I do a long loop without a declared element
identifier, I will usually assigned a named variable to a function of $_ as my first 
line.

foreach (@words) {
   my $dictiionary_entry = lc $_;
   ...
}

Joseph



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




Re: could use an audit

2003-12-13 Thread drieux
On Dec 12, 2003, at 4:20 PM, Kenton Brede wrote:

I've cobbled some code together that will allow me to parse a file
snarfing 4 lines which consist of server name and Daily output of
bandwith usage.
[..]
I'm not exactly a programming wonder and trying to learn.
[..]

Kent,

As has been noted, james has covered most of the salient GP coding
features - so I am left once again to play 'thinking outside
of the box'. First off thanks for the nicely formatted data
and 'real world' issue to play with.
My extension to your basic problem is based on the classical
"multi-homed" host, one with more than one NIC card in it. Given
that some of our readers are not sure how to work with 'hashes'
I thought I would take the time to marry the two concerns.
I have posted the demonstration code at:

So My first step was to come up with data model,
which presumed no more of the 'incoming' information
than that
	* 

told me that the following records would be about
that host - whether that meant a single data set
about One Or More Nic's, or the case that we would
have information about a single nic for that hostname
and would find more nic information later on for
that same hostname...
Since I am a fan of perl's subs, since they are a
leading cause of Perl Modules, I thought I would start
with one sub, decide that I wanted to go off in a different
direction. Comment out the first call to that sub, and
replace it with a 'cooler' sub This should also help
illustrate a way of 'evolving' code forward.
Have fun.

ciao
drieux
---

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



Re: Parentheses

2003-12-13 Thread drieux


Thought I would propose one more argument on
the 'importance' of parens and subs.
While putting together

I of course had my usual devolutions, because It
is easier, for me, to put a RegEx in a function
that I will call twice, than have to go through
the cut and paste clean ups on two lines, if I
change my mind.
so while it is possible to do

	$rx_line = get_number_from_line $rx_line;

this will require that the get_number_from_line()
is either pre-declared, or will always be a sub
prior to the current one. So in exchange for
the extra typing of the parens, I gain the
liberty to not have to worry when the perl compiler
gets around to resolving that I meant it to be a
function I do not have to maintain the
functions in a given order, nor maintain a list
of pre-defined functions.
ciao
drieux
---

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



Re: Use of uninitialized value in pattern match (m//) at ./getopt.pl line 14.

2003-12-13 Thread drieux
On Dec 13, 2003, at 10:01 AM, Wiggins d'Anconia wrote:
[..
A decent template, any gurus have improvements?
[..]

my stock gag, looks like:

my $opt = parse_cmd_line_options();
...
#---
# These are the Subs for the parse_cmd_line_options.
#---
# The Usage Command so that we can use a common interface to
# handle both the cases where we want to show some basic detailed
# information with a '--help' query, as well as to exit out of
# the parse_cmd_line_options wrapper for Getopt::Long if we have
# problems with user generated commands.
#---
sub Usage
{
my($msg, $retval, @list) = @_;
print "$msg\n" if ($msg);

print "Usage: $0 [-i|-x|-c|--kadb] [-f ] [-d 
]\n";
if ( @list ) {
print "  the full optins list is:\n";
print "\t$_\n" foreach (@list);
}
exit($retval);
}

#
# where we wrap the Getopt::Long and resolve which arguments
# work and play well with other command line arguments.
#
# 
$ref->{'delete'} = [];
#
# more editorializing
#
$ref->{'add'} = [] ;
#
# this also doubles as the flash guide. in Usage
#
my @list = qw/
file|f=s
import|init|i
installdb
export|x|e
compact|c
delete|d=s
add|a=s
fsck
nup
kadb
help|h|?/;
   my @config_args = qw/bundling/;
Getopt::Long::Configure(@config_args);
my $results = GetOptions($ref, @list) ;

Usage('Problem with Input Arguments',1,@list) unless ($results);

Usage('The General Help',0,@list) if ($ref->{'help'});

#
# now to create the action station section
#
#sort out other gory details about the which arguments
#should or should not be dealt with
$ref ;

} # end of parse_cmd_line_options

This dog has soldiered on in one variant or another...

vladimir: 41:] ./db_tool.plx --kadb
option: help
we have the following options:
add  [sysname config_host] -> add sysname and config_host to db
delete [sysname ]  -> delete sysname from db
show_sysnames  -> list current sysnames in db
config_host-> get config_host for sysname in db
export -> export db to file
import -> import file to db
q|exit|quit-> exit kadb
option: q
exiting
vladimir: 42:]
the '--kadb' started out as a bad JOKE, I whined at
myMostGloriousLeader that just for him, I would offer
up a 'kryptic command line interface with short and
arcane syntax, you know, just like kadb' IT
HURTS when one stops laughing and has to implement
it in a rush because, well, one just needs it down and dirty,
but it has to work...
I went with the 'bundling' approach so that the
'oldGuy' *nix freaks would be 'happy' while the
gnuSters would be able to wander the plains with
their --help and the like...
ciao
drieux
---

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



Re: Win32::SerialPort to log file

2003-12-13 Thread drieux
On Dec 12, 2003, at 7:06 PM, [EMAIL PROTECTED] wrote:

I'm trying to get a script to save a barcode scanner's output to a log  
file.
[..]

do you mean that you are using



use Win32::SerialPort;
# use strict;
use warnings;
[..]

you might want to uncomment the use strict.

$LOGDIR= 'c:\perl\scripts';  # path to data file
$LOGFILE   = "router.log";# file name to output to
$PORT  = "COM2";  # port to watch
[ cutting out a prior effort to new the widget ]
#
# open the logfile, and Port
#
open(LOG,">>${LOGDIR}/${LOGFILE}")
||die "can't open smdr file $LOGDIR/$LOGFILE for append:\n";
then deal with the problem here:

$ob = tie (*BIFF, 'Win32::SerialPort')
   || die "Can't tie: $^E\n";
$PortObj = tie (*FH, 'Win32::SerialPort', $Configuration_File_Name)
   || die "Can't tie: $^E\n";## TIEHANDLE ##
from the pod would seem to suggest that you would
want to have a configuration file???
select(LOG), $| = 1;  # set nonbufferd mode

#
# Loop forver, logging data to the log file
#
while($_ = ){# print input device to file
print LOG $_;
}
[..]

you could do this logging part as

	print LOG $_ while();

which will just woof what ever you got from
the bar_code Reader.
HTH...

ciao
drieux
---

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



Split question

2003-12-13 Thread Perl
Hi,
   i am new to Perl.
   here is my question 

  i have a character string like abc#def#ghi#jkl

  i want to split the string based on the delimiter # so that i get 
something like this :

  abc  def  ghi jkl

  But
  
  @temp = split(/#/, "abc#def#ghi#jkl") ;

doesn't seem to work.

am i doing anything wrong here ?

thanks,
S.





-
Do you Yahoo!?
New Yahoo! Photos - easier uploading and sharing

Re: Split question

2003-12-13 Thread John W. Krahn
Perl wrote:
> 
> Hi,

Hello,

>i am new to Perl.
>here is my question 
> 
>   i have a character string like abc#def#ghi#jkl
> 
>   i want to split the string based on the delimiter # so that i get
> something like this :
> 
>   abc  def  ghi jkl
> 
>   But
> 
>   @temp = split(/#/, "abc#def#ghi#jkl") ;
> 
> doesn't seem to work.
> 
> am i doing anything wrong here ?

Nothing.

$ perl -le'
@temp = split(/#/, "abc#def#ghi#jkl");
print for @temp;
'
abc
def
ghi
jkl



John
-- 
use Perl;
program
fulfillment

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




Re: Split question

2003-12-13 Thread Kenton Brede
On Sat, Dec 13, 2003 at 09:16:35PM -0800, Perl wrote:
> Hi,
>i am new to Perl.
>here is my question 
> 
>   i have a character string like abc#def#ghi#jkl
> 
>   i want to split the string based on the delimiter # so that i get 
> something like this :
> 
>   abc  def  ghi jkl
> 
>   But
>   
>   @temp = split(/#/, "abc#def#ghi#jkl") ;
> 
> doesn't seem to work.
> 
> am i doing anything wrong here ?

As John mentioned your split function is working correctly.  What
"doesn't work?"  If you post more of your code it would be helpful.
Kent


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