RE: in a regex- re-arrange $1..$n

2004-10-12 Thread West, William M


>Are you thinking of :
>
>( $a1,$b1,$a2,$b2,$a3,$b3,$a4,$b4,$a5,$b5 ) = $_ =~ /regexp/  ?

that might be what i need-  if i'm going to be working with these values
alot, then i want to know what they are at the outset

>
>The result of a regexp ($1..$9) are returned in array context, so you
can
>either assign them to an array
>
>@data = $_ =~ /regexp/
>
>or return them to named variables as above.
>
>I use the above, because I can't stand using '$1' '$2' '$3' etc for
more
>than
>two lines of code below the regexp capture, because context is lost to
>the reader.


exactly!  i have enough trouble with the regex itself to worry about
what the captures refer to.  

I'd forgotten about matches returning in a list context- no s///
required.



thanks,

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

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




RE: in a regex- re-arrange $1..$n

2004-10-11 Thread West, William M



>-Original Message-
>From: Wiggins d Anconia [mailto:[EMAIL PROTECTED]
>Sent: Monday, October 11, 2004 3:14 PM
>To: West, William M; [EMAIL PROTECTED]
>Subject: Re: in a regex- re-arrange $1..$n
>
>> the following is an as yet incomplete regex that i'm working on:
>>
>> $data = $_ =~
>>
s/<(name)>(.*?)<(desc)>(.*?)<(copy)>(.*?)<(license)>(.*?)<(entry)>//xg
>>
>>
>> every other capture ($1 $3 $5 $7 $9) is going to be used one way, the
>> other
>> captures will be used differently...  i'm wondering if there's a way
to
>> force the captures into particular numbered variable, so that
>> $1 =$1
>> $2 = $3
>> $3 = $5
>> $4 = $7
>> $5 = $9
>>
>
>How about just not capturing them to begin with?  If you add C to
>the beginning of your capture it will ignore the capture.  Having said
>that, why are you capturing to begin with if you are just going to
throw
>them away?  The parens in your example don't matter for the match to
work.


you misread- i intend to USE all of the captures- but i wanted to
categorize them more easily by "type", so ?: would be useless.

>
>> etc...  or is it even worth it for easier coding later on?
>>
>
>At the very least I would switch to named variables to make it more
>readable and prevent the chance that they get clobbered by a later
regex.

what i am likely going to do is finish the processing in the one s///,
so leaving them as is might not be a problem.   


i've worked on this since my last post::

$_ =~ s/<(.+?)>(.*?)<(.+?)>(.*?)<(.+?)>(.*?)<(.+?)>(.*?)/
$css{$1}{open} $2 $css{$1}{close}
$css{$3}{open} $4 $css{$3}{close}
$css{$5}{open} $6 $css{$5}{close}
$css{$7}{open} $8 $css{$7}{close}/xg


%css is an HoH- using half the captures as keys etc...   looks like this
will work well enough for me after all :)  

but i'm still wondering about the original question... with so much time
spent by me with regexen, i'd love to keep them as readable and
malleable
as i can.




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

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




in a regex- re-arrange $1..$n

2004-10-11 Thread West, William M
the following is an as yet incomplete regex that i'm working on:

$data = $_ =~
s/<(name)>(.*?)<(desc)>(.*?)<(copy)>(.*?)<(license)>(.*?)<(entry)>//xg


every other capture ($1 $3 $5 $7 $9) is going to be used one way, the
other
captures will be used differently...  i'm wondering if there's a way to
force the captures into particular numbered variable, so that
$1 =$1
$2 = $3
$3 = $5
$4 = $7
$5 = $9

etc...  or is it even worth it for easier coding later on?






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


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




RE: pass a filehandle then use it in grep{}?

2004-10-08 Thread West, William M


>Right. readdir() expects a DIRHANDLE as the argument, while grep()
>expects a LIST as the second argument.
>
>> which is fine- my careless reading of my other code got the misuse
>> of <> stuck in my head-  that kept me from seeing the proper
>> solution.
>
>Make it a habit to study the docs for the functions you are using:
>
> perldoc -f grep
> perldoc -f readdir


oddly- the grep documentation in perldoc doesn't even mention
filehandles.  readdir does show proper use though- when i looked up grep
in the perldocs, the issue remained unclear to me.  But, of course, it
was my self induced "blindness" that kept me from seeing the solution.

Now, a   might be seen in a list context- but connecting
that to grep {code} @list; was just too much for my little brain to
handle at that time *laugh*

>
>--
>Gunnar Hjalmarsson
>Email: http://www.gunnar.cc/cgi-bin/contact.pl



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


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




RE: pass a filehandle then use it in grep{}?

2004-10-08 Thread West, William M



> Gunnar Hjalmarsson wrote:
>>> William M West wrote:

@creds = grep {/./} $fh;
>>>
>>> Try:
>>>
>>> @creds = grep {/./} <$fh>;
>>
>> ah!!  i was so used to that /not/ being the case with a normal
>> filehandle
>
>Don't understand. Which syntax(es) are you referring to when saying
that?

my @array =grep {-d "$directory\/$_"} readdir ;

gives me this error::

Type of arg 1 to readdir must be HANDLE (not ) at ./subdirs.pl
line 30, near ";"
Execution of ./subdirs.pl aborted due to compilation errors.


but of course that's NOT the same as :
my @array =grep {/foo/} ;


which is fine- my careless reading of my other code got the misuse of <>
stuck in my head-  that kept me from seeing the proper solution.



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

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




RE: pass a filehandle then use it in grep{}?

2004-10-06 Thread West, William M



>> @creds = grep {/./} $fh;
>
>Try:
>
> @creds = grep {/./} <$fh>;
>
>--
>Gunnar Hjalmarsson
>Email: http://www.gunnar.cc/cgi-bin/contact.pl

ah!!  i was so used to that /not/ being the case with a normal
filehandle that i didn't think to use it with a reference

*laugh*  

thank you :)  i'm going to go play with Benchmark and see what that
gives me




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


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




pass a filehandle then use it in grep{}?

2004-10-06 Thread West, William M
this does not work:

sub extract{
#retrieve subset of data from a single file
#return that data in a list context

my $fh = shift; #filehandle reference
my @creds;
local $/ = '';
@creds = grep {/./} $fh;
@creds
}


this does work::

sub extract{
#retrieve subset of data from a single file
#return that data in a list context

my $fh = shift; #filehandle reference
my @creds;
local $/ = '';
for (<$fh>){ push @creds,$_};
@creds
}




the first returns *main::IN
the second returns the actual data that i want.

i looked at perldoc perlref and the camel book- tried different ways of
doing things- but i must be missing something!!! 

I doubt that one is much better than the other for what i want to do,
but i would like to understand why i can't do it the first way.

*sigh*


thanks :)

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


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




RE: speed of grep{s///} vs ??? or am i asking the wrong question?

2004-10-05 Thread West, William M



>-Original Message-
>From: Bakken, Luke [mailto:[EMAIL PROTECTED]
>Sent: Monday, October 04, 2004 5:06 PM
>To: West, William M; [EMAIL PROTECTED]
>Subject: RE: speed of grep{s///} vs ??? or am i asking the wrong
question?
>
>Try this, you don't need to shell out. It returns an array of
>subdirectories.
>
>opendir LS, $directory or die "Can't opendir $directory: $!";
>my @dirs = grep { -d $_ } readdir LS;
>closedir LS;
>return @dirs;

thank you this is much more readable code too me- but i found out that
you need a fully qualified path...


>my @dirs = grep { -d $_ } readdir LS;
should be:

my @dirs = grep { -d "$directory\/$_" } readdir LS;

or something of the sort...  took me a long long time before i finally
looked it up here: http://www.perlmonks.org/index.pl?node=readdir


hmmm..  with 1 iterations here's a benchmark::


   Rate sub_with_substitution  sub_with_readdir
sub_with_substitution 410/s--  -35%
sub_with_readdir  633/s   54%--


using readdir seems to take a bit less time... while i'm typing this,
i'm testing with 10 iterations.

Here is the benchmark script::



#!/usr/bin/perl


use strict;
use diagnostics;
use Benchmark qw/cmpthese/;


sub get_subdirectories{
# retrieves list of directories from passed directory
#returns list as an array

my $directory = "/home/corenth";
open LS, "ls -l $directory|";
local $/ = undef;
#my @dirs =
grep {s/^d.*?\s*?(\w*)$/$1/} split ( /\n/, );


}


sub get_sb2 {
 # retrieves list of directories from passed directory
#returns list as an array

my $directory = "/home/corenth";
opendir LS2, $directory or die "no opendir $directory: $!";
#my @dirs =
   my @array =grep {-d "$directory\/$_"} readdir LS2;
closedir LS2;
return @array;

}

my @results = get_subdirectories("/home/corenth");
my @results2 = get_sb2();
print "@[EMAIL PROTECTED]";



cmpthese(10,{
sub_with_substitution =>\&get_subdirectories,
sub_with_readdir => \&get_sb2,
});


__END__



looks like readdir()  is the all around winner :)



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

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




speed of grep{s///} vs ??? or am i asking the wrong question?

2004-10-04 Thread West, William M

here's what works for me so far:

#!/usr/bin/perl


use strict;
use warnings;

sub get_subdirectories{
# retrieves list of directories from passed directory
# returns directory list as an array

my $directory = shift;
open LS, "ls -l $directory|";
local $/ = undef;
my @dirs =  grep {s/^d.*?\s*?(\w*)$/$1/} split ( /\n/, );


}


my @results = get_subdirectories("/home/corenth");

print @results;

__END__
---

now-  just curious about speeding it up- pehaps a module would be fine,
but i'd like to try this out explicitly. -- i think the s/// is what
bothers
me most.  since i'm not all that comfortable with map() and grep()
especialy in block form (perldoc -f grep and perldoc -f map)  i'm not
sure if what i'm doing really takes advantage of the features that these
functions have to offer.

any advice?

thanks :)

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


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




RE: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-10-04 Thread West, William M


>William> My impression was that OO in Perl has historically been
fraught
>with
>William> CPU overhead - this will change in Perl 6?  (argument number
2)
>
>FUD FUD FUD.
>
>*All* late binding takes a bit of time.  Perl caches what it can.
>


well, i'll be a mother's son!  I figured that Perl had to have /some/
problems somewhere.

interesting.


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


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




RE: sum a column

2004-10-01 Thread West, William M
>
>But I didn't say that about the script author, and you claim to be the
>script author, so what's the problem?
>
>--
>Gunnar Hjalmarsson
>Email: http://www.gunnar.cc/cgi-bin/contact.pl


looks like a communications problem...  

"The script author does have a clue about programming."

is easy to misread as saying "does not" if you pass your eyes over it 
quickly...i did that the first time i saw it... *shrug*  





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


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




RE: Becoming Disenheartened - Everyone talks about Python and says Perl is old news.

2004-10-01 Thread West, William M
>With this willing to treat everything as object you end up with
>Ugly code such as the following:
>http://www.python.org/cgi-bin/moinmoin/CgiScripts

(code snipped to save space)


i found the Python script to be very readable- i am far more comfortable
with Perl syntax, but it worked for me.

I think there are two arguments which can be made here- both good.

1.  code syntax (limitation/flexibility/readability) - how languages
differ and language preference.

2.  Language strengths and weaknesses (outside of syntax).


My impression was that OO in Perl has historically been fraught with 
CPU overhead - this will change in Perl 6?  (argument number 2)

I like the functional() as apposed to the menthod.syntax() because i can
more easily visualise the path that data takes through the code.  makes
my life easier (argument number 1)


for me something like $new_s = change($s, $string); just works better
for me.  anyway, the advantages of encapsulation are easily produced in
functional() code with good coding practices.

of course, now we're talking about meta topics as apposed to particular
Perl
questions- but I think the argument is worth while.


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


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




substitution and assignment fun ( was RE: Becoming Disenheartened )

2004-10-01 Thread West, William M


>
>Python and Ruby don't write the code for me. But look at this Python
code:
>
>s = "I am Perl guru";
>new_s = s.replace("Perl", "Python");


i always had trouble doing this in perl- just worked around it- then
realized that this shouldn't be hard when reading your post... so i
played...

$s = "I am Perl guru";

$new_s = ($s =~ s/erl/ython/);

print "$s \t $new_s \n";  #oops!  PrintsI am a Python guru
1"

#but

($new_s = $s) =~ s/erl/ython/;
print "$s \t $new_s \n";  

#prints   I am a Perl guru  I am a Python guru


Perl can be surprisingly intuitive-  using precedence rules to get this
done makes good sense to me :)




>Huh? Remark, no addition modules.


*shrug*  eh- go figure



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

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




RE: feeding standard input calling an external program

2004-09-07 Thread West, William M


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

>
>> #try this: system("echo \'$xml\' | myprogamname")
>>
>>  \ i haven't tried it, but it
>> should keep the shell from interpolating the xml data
>
>But what happens if the XML has an embedded apostrophe ?
>
> $ echo 'Monty Python's Flying Circus'
> >
> ^C
>
>Or some other magical character ?
>
> $ echo 'D'oh!'
> -bash: !: event not found
> $
>
>D'oh!

your're right!!! i'd forgotten that- i've used a solution as follows:

$DATA  =~ s/(\w\w)/chr (hex($1))/eg;

this converts hexadecimal back to a string - funny chars and all from within
a perl program that's called via `myprog.pl` etc   i don't remember how
to convert the string INTO hex-  but doing that, then modifying the other
program to decode it accordingly may do what you want it to.


>There's all kinds of edge cases that would have to be dealt with here. I
>really think that putting the XML directly into a command line is doomed
>to failure; putting it in a temp file should be much more robust.

i agree.. but the above might work for this person.


>Chris Devers




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



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




RE: feeding standard input calling an external program

2004-09-07 Thread West, William M

>
>
>One way to do this -- probably not a good one -- might be
>
> system("echo $xml | myprogamname")
>
>but if there's anything in the XML that the shell finds interesting,
>this could fail in all kinds of spectacular ways.

#try this: system("echo \'$xml\' | myprogamname")

\ i haven't tried it, but it
should keep the shell from interpolating the xml data


>--
>Chris Devers


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




RE: Reading hex data from file.

2004-08-19 Thread West, William M
>Hi,
>Among other data, a binary file contains the bytes "00A5".
>I am trying to read these four bytes and get the decimal equivalent as




-


$POST_DATA =~ s/(\w\w)/chr (hex($1))/eg;

this is a line from one of my programs where i send data from another
program in the form of arguements-  yea, i'm sure there's a better way...
*laugh*


after much experimenting, this gave me the ascii equivalent of a string of
hex values.   i'm willing to bet that with modifications, you can get
yourself a decimal equivalent 


good luck,



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


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




RE: C Compiler

2004-08-04 Thread West, William M

>
>Any recommendations on a c compiler to run on a Sun Sparc box?
>
>Rob


this is bordering on off-topic, but since a compiler is useful
for certain Perl modules, 

 go get gcc

http://gcc.gnu.org/install/binaries.html


this is a page to get gcc when you can't compile it yourself.  now, i didn't
see sparc mentioned on the page- wasn't looking too terribly hard.


good luck 

:)


willy


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




RE: question about ( () if () ) while ();

2004-08-03 Thread West, William M

>Check 'perldoc perlsyn'.  It explains that the "statement modifiers",
>things like '... if CONDITION' and '... while CONDITION' are only allowed
>after *simple* statements -- what they really should say is "expressions".
>
>You're allowed to write
>
>  print 1 if /willy/;
>
>because 'print 1' is an expression.  You can't write
>
>  print 1 if /willy/ while ;
>
>because 'print 1 if /willy' is not an expression, it's a statement.
>

well, this restriction has forced me to come up with:

perl -e ' $entry = "willy"; (print /$entry/) while ($_ = "wil"); print "0"'


in this test it ends up not getting to print "0", but with a match it works
great :)   i can apply it properly now when substituting a filehandle for
the expression in the while.


thank you!

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

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




question about ( () if () ) while ();

2004-08-03 Thread West, William M

$ perl -e ' $entry = "willy"; (print "1") if (/$entry/) while ($_ = "will");
print "0"'
syntax error at -e line 1, near ") while"
Execution of -e aborted due to compilation errors.




seperating the bits seems to work.  it seems to break down when i want to
use the if statement in combination with the while.


using print to simulate return values.


perhaps i should abandon this idiom and use a normal  

while () {
if () {

}
}


i am curious as to why this error crops up...


thanks,



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


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




RE: Perl <-> Expect

2004-07-15 Thread West, William M
>>
>>
>>Hi,
>>
>> >I need to telnet some hosts automatically without supplying password.
>> >I can do it with Expect but I hardly know the language.
>> >I wonder what you think of the Perl module Expect - if it's any good and
>> >easy to use.
>> >Also if you can think of another way to do the job this will also be
>>great.


I've used expect before- i don't have the script with me :/

I'll try to dig it up... 

Also, using Net::Telnet can work... it's a little more complex,
but feels more like Perl :) well, it /is/ Perl... *laugh*


if you use expect then here is one way to do it :

open (IN, "$expect_script |");#pipe the output of the expect script
#to a filehandle

while (){
manipulate data
}

you can't do much to manipulate the expect script here, but it lets you grab
the results.


If you want a Perlish way to login outomatically, look at the Perl expect
module (i haven't - and i understand it's a bit complicated) or look at
Net::Telnet.  I recommend the latter.  It may be complex, but the
documentation is fairly complete.  It will take practice getting used to it.


regards,

willy



http://www.hackswell.com/corenth 


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




RE: Pop up calendar

2004-07-12 Thread West, William M


>On Mon, 12 Jul 2004 00:29:52 -0700 (PDT), [EMAIL PROTECTED] (Melis
>Mutlu) wrote:
>
>>Hi,
>>
>>I have a form with a date field (created by
>>CGI::Quickform). I would like to add a pop up calendar
>>so I can pick dates easily. Does anybody know how I
>>can do that? Is there any module I can use for that?
>>
>>Regards,

This idea will give you a calander embedded inside the webpage.
If you want a seperate window to pop-up i think
that's also possible without the use of java etc.

anyway...


There is a program called cal(1)  which produces output like:

  July 2004
Su Mo Tu We Th Fr Sa
 1  2  3
 4  5  6  7  8  9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31



doesn't quite look right after copy past...

this is not portable to Win32 unless there is a perl module that 
will give you similar results.

you can wrap the data into a   structure.

first :
while (`cal`){
push (@array , $_); 
}  

then:
foreach (@array);
@dates = split (/\s/, $_);
push (@dates , '');
   }


now you have each item in a seperate element on @dates along with an extra
'' to
help us see where the line breaks are-  you can add form data based on the
contents of the
@dates array.


foreach (@dates){
$data .= '< formsubmitdata >'. $_ .'';
if ($_ is a linebreak){
$data . = ''; #if wrapped in a table?
}

not well written, but i think it will give an idea of what you might do.

the concatonation operator '.' makes life much easier when i try this stuff



i'll try to do this myself i think :)


thanks,
 willy

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




Mail Server in Perl on Win32 platform.

2004-06-08 Thread West, William M

Am trying to get Activestate Perl to run a Mail server...

been searching CPAN and found Net::Server::Mail::SMTP.

the line:
my $smtp = new Net::Server::Mail::SMTP socket => $conn;

gives me the error:
--
Can't locate object method "new" via package "Net::Server::Mail::SMTP" at
testserver3.pl line 11.
--

when I try to send mail through it.

I would very much like to have a working mailserver- no need for security ..
just a simple server.

the server code follows::

(straight from the CPAN documentation)
(http://search.cpan.org/~rsoliv/Net-Server-Mail-0.08/lib/Net/Server/Mail.pm)


use Net::Server::Mail::SMTP;

my @local_domains = qw(example.com example.org);
my $server = new IO::Socket::INET Listen => 1, LocalPort => 25;

my $conn;
while($conn = $server->accept)
{
my $smtp = new Net::Server::Mail::SMTP socket => $conn;
$smtp->set_callback(RCPT => \&validate_recipient);
$smtp->set_callback(DATA => \&queue_message);
$smtp->process;
}

sub validate_recipient
{
my($session, $recipient) = @_;

my $domain;
if($recipient =~ /@(.*)>\s*$/)
{
$domain = $1;
}

if(not defined $domain)
{
return(0, 513, 'Syntax error.');
}
elsif(grep $domain eq $_, @local_domains)
{
return(0, 554, "$recipient: Recipient address rejected: Relay
access denied");
}

return(1);
}

sub queue_message
{
my($session, $data) = @_;

my $sender = $session->get_sender();
my @recipients = $session->get_recipients();

return(0, 554, 'Error: no valid recipients')
unless(@recipients);

my $msgid = add_queue($sender, [EMAIL PROTECTED], $data);
  or return(0);

return(1, 250, "message queued $msgid");
}




thank you,
   willy


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




RE: installing perl module without root permission

2004-05-03 Thread West, William M
>gohaku> What if perldoc is not included for some reason?
>
>All perl distros (except macperl for os 9) in the past eight years
>or so have "perldoc".

oddly enough- my Knoppix install does not... i'll have
 to remedy that someday...

willy

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




RE: Replace ' ???

2004-04-27 Thread West, William M
>
>I have a function and can't seem to get this figured out.  I have
>apostrohe's in the file that I am pulling down, however I need to remove
>all
>of the apostrophe's from the file before putting the file into the system.


1.  I'm not sure if ' has to be escaped when in a regex... so
try one the following:

s/'//g #get rid of all ' from the line

or
s/\'//g #same as above, but using the \ to escape the ' just in case the '
  #does some funny things in a regular expression.

willy 

:)

-- 
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: ways I might parse data in perl and give it to a telnet sessi on

2004-02-19 Thread West, William M

>Is there any separate reason to use 'expect' Perl will happily
>talk telnet and ftp on its own.
>
>Rob


well- namely that it works- i honestly don't know /how/ to get perl
to talk telnet *laugh*  i guess the proper module would help.

i will investigate this possibility and see what happens :)

off to CPAN.

ttfn,
willy


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




ways I might parse data in perl and give it to a telnet session

2004-02-18 Thread West, William M

definitions::   'cuecat' is a barcode reader
'expect' is a scripting language that lets you
automate
actions with interactive programs such as
'ftp'
or 'telnet'.

what i am trying to do::

1 translate cuecat data(done via larry wall's perl script- don't 
  have URL).
2 write data to an interactive program.


this last is giving me fits.  possible ways::

write data to file.  slurp up file with an expect script.  this 
script needs to be constantly running- logging in to the 
system i use is a pain otherwise.  i do not yet know how
to slurp the data with expect.

pipe or write data to said expect script directly from the perl 
script instead of writing the data first to a file.  i do not know 
how to do that kind of inter-process communication.

use the (an?) expect module for perl- i know of one,
but the syntax looks darn right scary to me and i already 
have a sense of expect- so i'd rather not learn the perl
version :P.  However, learning the perl version removes
the need for inter-process communications.  as long as i can
preprocess the keyboard (or cuecat) input, then send it to the 
interactive program (telnet session) i should be fine.


the questions are::


1)  has anyone had experience with this kind of project?
2)  which of the above would be the most likely path for
me to follow?
3)any alternate methods?




thanks,
willy :)

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




RE: skipping lines of input from another program...

2004-02-09 Thread West, William M


>
>I think you have an over-elaborate design for this anyway. I think it's
>likely that your data can be processed better than just by skipping 'n'
>lines between useful records. And even if this is the way you want to go
>there's nothing wrong with

well- my design is likely not that great over all *laugh*
but it works well enough :)   i have taken your code below and
am implementing it--  i think it's clearer what's going on.

>
>   for 1 .. $skip->[0]
>  my $partnumber = ;
>
>   for 1 .. $skip->[1]
>  my $inventory = ;
>
>HTH,
>
>Rob

when i tried the " for 1 .. $n;" idea, at first i wanted to use $_ 
again...  i finally understand that it's not being assigned any value at
this point- it still retains the last value from  the while loop...


i wanted to take 

while (){
$x = $_;
}

and simply insert your line like so::

while (){
 for 1 .. $borkborkborkbork;
$x = $_;
}

for me this is a more intuitive idiom, though one i 
now know to be false.


while (){
 for 1 .. $borkborkborkbork;
$x = ;
}

seems to be the proper (only?) method in this particular case.



:)

thank you,
willy


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




RE: skipping lines of input from another program...

2004-02-06 Thread West, William M


in the post that i am now replying to, i said that i couldn't get
the program to skip lines as it parsed through the output of another 
program.

i have "solved" the problem- but i do not know WHY this works the 
way it does.





this worked great :)  (thanks to drieux) - in fact, it would let 
me have several programs input to this one at once :) (if i'm not mistaken)

>open (CMD , "$command|") or die "Could not execute $command : $!";
>
>parse_and_extract($pattern,$skip,$table);
>
>close CMD;





>
>sub skip_lines {
>   my $lines = shift; #number of lines in file to skip over
>
>   print "in skip_lines() $_ before skip\n"; #debug
>
>   # for 1..$lines; #not functioning...
>
>   for (0..$lines){
>   my $trash = ;
>   print "trash is $trash \n"; #debug
>   }


the fix was to replace the above for loop with the following::

for my $trash (0..$lines) {
$_ = ;
print "the line skipped is $_\n"; #debug
}




>   print "in skip_lines() $_ after skip\n"; #debug
>
>}



well- i don't understand it.  WHY does this work?

if someone could clarify the mechanics behind this behaviour,
i would be very grateful!



thank you much,
   willy



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




skipping lines of input from another program...

2004-02-06 Thread West, William M


the following is my script that i am working on- it fails to do
quite
the right thing.. qouting from one of the comments below::

"#skip_lines() is supposed to "skip" some lines of output.

#The problem is, that it DOESN'T even though the debug print statement
# "print "trash is $trash \n"; #debug " shows that it works-

#after leaving the for loop, it seems that CMD re-winds itself...
# i am flummuxed!!"




#!/usr/bin/perl
#
#
# Screen parser for Service Information System utilities
# on RAXP
# History::
#   5 feb 2004  skeleton and parse routines built (w/ test values.) wmw

#-

use strict;
use diagnostics;

#--
my $command = "/home/willy/Documents/conditional.testbed.exp";
my $pattern = "inittab";
my $skip;
   $skip->[0] = 2;
   $skip->[1] = 2;
my $table;
   $table->{"PART"} = "INVENTORY";
#--

# $pattern is only a string right now because i am assuming
# that the screens will be consistant with each call. $skip should produce
# enough flexibility for reuse.




open (CMD , "$command|") or die "Could not execute $command : $!";

parse_and_extract($pattern,$skip,$table);

close CMD;


#the following routine takes each line of the input (from a different
#program).  When the pattern is matched, it calls get_inventory().


sub parse_and_extract {

my $pattern = shift; #what we look for.

my $skips   = shift; #array ref. each value is # of lines to
skip
   # over.

my $table   = shift; #values are stored here. (hash reference)

while () {
get_inventory ($table,$skips) if ($_=~m/$pattern/);
print "parse_and_extract\n\r"; #debug
print "$_\n\r"; #debug
}
}

#the following routine assigns a key/value pair to a hash reference ($table)
#skip_lines() is supposed to "skip" some lines of output.

#The problem is, that it DOESN'T even though the debug print statement
# "print "trash is $trash \n"; #debug " shows that it works-

#after leaving the for loop, it seems that CMD re-winds itself...
# i am flummuxed!!

sub get_inventory {
my $table = shift;
my $skip = shift;


#$skip is an array reference for the case that several
#different screens will have to be parsed in the future-
#in which case, a flag will have to be added to determine
#which value in the array reference will be used.
# (perhaps $skip should be a hash of arrays?)

#first we skip the lines from the pattern match up to
#the line with the value we want.

skip_lines ($skip->[0]);

my $partnumber = $_;#check syntax-> is $_ instead?

#skip lines to the next value...

skip_lines ($skip->[1]);

my $inventory = $_;#check syntax-> is $_ instead?


$table->{$partnumber}=$inventory;
#print "keys:: "; #debug
#print keys(%$table); print "keys to the table\n"; #debug
#print " get_inventory() $_\n"; #debug

}


sub skip_lines {
my $lines = shift; #number of lines in file to skip over

print "in skip_lines() $_ before skip\n"; #debug

# for 1..$lines; #not functioning...

for (0..$lines){
my $trash = ;
print "trash is $trash \n"; #debug
}
print "in skip_lines() $_ after skip\n"; #debug

}



#---


the following is the test expect script that i am using- as far
as i can tell, it's working fine :/  (there's extra stuff in there
since i was trying to learn how to use "if" statements earlier...)




#!/usr/bin/expect -f

#set ps $argv 0
set ps "password"

spawn telnet "localhost"
expect "ogin: "
send "willy\n"
expect "word:"
send "$ps\n"

expect "terminal:*"  

send "ls\n"


#--

set file "Desktop.ini"

set counter 1
while {$counter < 5} {
send "echo $counter \n ls $file\n"

expect "No such file" {set counter [expr $counter + 1]}
expect "$file" {set counter 200}

sleep 2
}


send "ls\n\n"

sleep 2;

expect "terminal" {
if {$counter < 200} {
global subject
set subject "failed to produce report"
#expect "terminal:*"
send "w\n"
 }

 if {$counter > 100} {
#expect "terminal:*"
send "date\n"
 }
}

expect "terminal"
send "cd /etc\n"
expect "terminal"
send "ls\n"

#--
interact





thanks,
   willy


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




RE: $PATH/expect_scripts/script.exp | $PATH/perl/script.pl

2004-02-04 Thread West, William M


i feel silly.  with regard to pipe catching::


while () {

print " $_, is a lovely string\n";

}


well, there's a simple answer to a simple question...



willy :)


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




$PATH/expect_scripts/script.exp | $PATH/perl/script.pl

2004-02-04 Thread West, William M

the subject describes my wishes.

what i really want to do is parse the screens of an
expect script through a perl script...  now, what i would like to
do is understand how to catch a pipe in perl, and how
my program will end up being different.

I looked up pipe in 'perldoc -q pipe' and 'perldoc -f pipe'

i'm having trouble parsing the information, so i'm looking 
forward to a little bit of extra enlightenment :)


thanks,
   willy




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




RE: copying complex data structures

2003-12-12 Thread West, William M
>use Storable;
>$arrayref_one = dclone( $arrayref_two );
>


aha



thanks :)

it's those details that make a program so much easier to make..

i noticed another poster asking about reference notations- i think that this

and Object Oriented programming have given me the most headaches on a 
conceptual level.  

while i've gotten a handle on references (i hope) tha OO stuff still gets to
me *laugh*


again thanks,
willy

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




copying complex data structures

2003-12-11 Thread West, William M


the following will not work:

$arrayref_one = $arrayreftwo; #it's just making a new name for the same
#reference.


the following works fine:

foreach my $a (0..$what){
foreach my $b (0..$why){
$arrayref_one->[$a]->[$b] = $arrayref_two->[$a]->[$b];

}
}

it would be nice to have something to copy complex data structures that
isn't going to be a code maintenance headache-  the above is dependent
on the data structure being a "2 dimensional array" of particular size.
i don't want that restriction.

any help would be apreciated :)

thanks,
willy


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




use of File::Find

2003-11-06 Thread West, William M

find (\&transfer, $path);

sub transfer {
my ($newpath, $oldstring, $newstring) = @_;
otherstuff ($oldstring, $newstring);

#   etc...


}


now- how do i pass parameters to transfer() when it's called 
with find??

i want the recursive fileprocessing to change file contents and
put the changed file in a mirrored directory structure-  i am
doing well enough making the program, but the documentation
had been hard to work with with regard to File::Find...

don't worry- i'm looking at perldoc File::Find too... :)

thanks all,

willy

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



RE: help if than else statement

2003-09-04 Thread West, William M
>The "==" operator checks two numeric values for comparison, returning true
>if they match
>The "eq" operator checks two string values for comparison, returning true
>if
>they match

oh dear!! i'd forgotten that detail.

sometimes i still get myself with this one.

willy


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



RE: help if than else statement

2003-09-04 Thread West, William M

>
>Can some one tell me way this does not work.
>
>
>
>if (@ARGV[0] = "-q"){print "it worked\n";}

try (@ARGV[0] == "-q")
  ^^ this got me too- the "==" compares values
 while "=" assignes the right side value to
lef
 side variable- so @ARGV[0] is given the
value of "-q" when you run your program-
since the 
 assignment is successful- a 'true' value
results
  you print "it worked\n"
 


have fun :)


willy

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



data recovery ext3 (was RE: Recover zip file via Archive::Zip)

2003-08-14 Thread West, William M
>
>Hello everyone,

__snipped stuff to do with zipped files___


>While I'm still off topic and speaking of data recovery, has anyone
>every recovered data from a ext3 filesystem after all utilities have
>been tried to repair them?  I've tried all the utilities off of
>freshmeat.net and nothing works.  I've got bad blocks and i-nodes.  Any
>suggestions are welcome and you can email me off list.
>
>Thanks,
>Kevin
>--
>K Old <[EMAIL PROTECTED]>

once, a couple of years ago, i used perl and some utility to recover
files from a doomed filesystem- i thought it was debugfs, but i looked it
up and am now not sure... i will try to find my perlscript...

the utility in question allows you to dump inodes as files into another
filesystem- if your disk has multiple partitions, or you have multiple
disks, you can dump your stuff there..

what the perl script did was to organize them into different directories
according to their timestamp.. then i installed a new system (redhat
something or other i think) and looked at the files with nautilous- which
figured out what /kind/ of file each was... a lot of manual work, but
well worth it.

saved images, text, and scripts/config files that way.

i will look for that script and post it tomorrow if i find it- no
sense letting it go to waste.


i just wish i could remember the utility that let me dump those inodes..

willy


:)




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



data recovery ext3 (was RE: Recover zip file via Archive::Zip)

2003-08-14 Thread West, William M


>While I'm still off topic and speaking of data recovery, has anyone
>every recovered data from a ext3 filesystem after all utilities have
>been tried to repair them?  I've tried all the utilities off of
>freshmeat.net and nothing works.  I've got bad blocks and i-nodes.  Any
>suggestions are welcome and you can email me off list.


as i had mentioned yesterday, i had written a script some time ago that
dealt a little with this.  i have since found it (or a version of it) in
dead tree form- so i retyped it and am sure there are several things wrong
with it.

i am not sure what all the components do anymore- i did not document it well
:P

now that i've looked at it, it's really for getting to files that are
unlinked etc. so i am not sure it will do you any good.

to bring this more on topic, i would like to see what ways something like
this can be improved- it served useful to me in the past, but i'm sure it
can be made more useful:::


#!/usr/bin/perl

# added proper things when retyping it:
use warnings;
use diagnostics;
use strict;
#---

my $cfile = "/tmp/commands.file";
my $filesystem ="/dev/hda6";
my @path = ("/tmp/recover","","/recover","",".ebu");  #making a path to put
my $date="Oct"; #just files from October#stuff later

open (OUT,">$cfile");
print OUT "open $filesystem\n";# i wonder what this is for?

foreach (`/sbin/debugfs -R lsdel /dev/hda6`){#why did i hard code /dev/hda6?

#debugfs let's me list a bunch of inodes and i stick the list in a file

m/(\d+)/;
$path[3]=$1;   #had to split this regex to dead with some edge case 
$1=~m/(\d)/;# but i can't recall what

$path[1]=$1;
my $quatch = join("",@path);
my $place= "path[0]$path[1]";
print OUT("dump <$path[3]> $quatch\n") if ((m/$date/));

`mkdir $place`;
}


-

then i chmod 755 command.file?  or is it a file used by another tool???

i just don't remember!!!

hope others can clarify?  

it's funny about code... since i've written this, i've learnt how to
document things far more completely



good lesson to learn!


willy

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



RE: data recovery ext3 (was RE: Recover zip file via Archive::Zi p)

2003-08-08 Thread West, William M

>From: Tassilo von Parseval [mailto:[EMAIL PROTECTED]


>Subject: Re: data recovery ext3 (was RE: Recover zip file via Archive::Zip)
>
>On Thu, Aug 07, 2003 at 03:09:06PM -0400 West, William M wrote:
>>
>> i am not sure what all the components do anymore- i did not document it
>well
>> :P
>
>Let me help. :-)

why thank you :)



>> now that i've looked at it, it's really for getting to files that are
>> unlinked etc. so i am not sure it will do you any good.
>
>Partly it might. The only problem with your script is that it cannot
>deal with data that is spanning more than 12 inodes (those were usually
>not in one block but fragmented over the harddisk). A line like this
>shows such a trickier example:
>
>99526  0 100644 6761321/1027 Sat Feb  2 09:11:58 2002

well.. this is interesting- i am not sure how to interpret this line
properly.  also, i assume that even split inodes will all get shoved through
the script... so, perhaps there is a way to concatonate/rename the split
inodes?  or is there no way to see which belongs to which group?


>
>I don't by hard know what to do with it, but it is laid out in the ext2
>undeletion how-to.

well- this gives me a place to start looking. :)

>
>> to bring this more on topic, i would like to see what ways something like
>> this can be improved- it served useful to me in the past, but i'm sure it
>> can be made more useful:::
>>
>>
>> #!/usr/bin/perl
>>
>> # added proper things when retyping it:
>> use warnings;
>> use diagnostics;
>> use strict;
>> #---
>>
>> my $cfile = "/tmp/commands.file";
>> my $filesystem ="/dev/hda6";
>> my @path = ("/tmp/recover","","/recover","",".ebu");  #making a path to
>put
>> my $date="Oct";  #just files from October#stuff later
>>
>> open (OUT,">$cfile");
>> print OUT "open $filesystem\n";# i wonder what this is for?
>
>Debug message?

no-> i wasn't all that sophisticated.. *shrug*  

>
>> foreach (`/sbin/debugfs -R lsdel /dev/hda6`){#why did i hard code
>/dev/hda6?
>>
>> #debugfs let's me list a bunch of inodes and i stick the list in a file
>>
>> m/(\d+)/;
>> $path[3]=$1;   #had to split this regex to dead with some edge
>case
>> $1=~m/(\d)/; # but i can't recall what
>>
>> $path[1]=$1;
>> my $quatch = join("",@path);
>> my $place= "path[0]$path[1]";
>> print OUT("dump <$path[3]> $quatch\n") if ((m/$date/));
>
>Essentially, from a line like
>
>2210070   1000 100600  228432/   6 Wed Jul 23 09:26:10 2003
>
>you extract the inode (2210070) and from that turn
>
>my @path = ("/tmp/recover","","/recover","",".ebu");
>
>into
>
>@path = ("/tmp/removed", 2, "/recover", 2210070, ".ebu");
>
>So the deleted inode gets dumped into
>
>/tmp/removed/2/recover/2210070.ebu
^^^--- typo!  *laugh*
>
>This could have been done more easily:
>
>@path[3,1] = /((\d)\d+)/;

fantastic!  i have never been terribly good with regexes and am trying to 
avoid learning them again until perl6  *laugh*  i must to too darn lazy!!


>
>> `mkdir $place`;
>> }



>>
>>
>> -
>>
>> then i chmod 755 command.file?  or is it a file used by another tool???
>
>command.file is the list of dump directives. It's supposedly a shell
>script that you can run later. So the above Perl script just generates
>another script. I am just not sure about
>
>> print OUT "open $filesystem\n";
>
>open /dev/hda6
>
>is not a meaningful command in shell scripts AFAIK.
>

i agree- but something is nagging at the back of my head, telling me that it
was useful perhaps it is readable by another command... instead of using
mount...  *sigh*  i don't know :P




>Tassilo


i'll try to rewrite it... see if i can get it to work again :)


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



RE: data recovery ext3 (was RE: Recover zip file via Archive::Zi p)

2003-08-08 Thread West, William M
>> now that i've looked at it, it's really for getting to files that are
>> unlinked etc. so i am not sure it will do you any good.
>
>Partly it might. The only problem with your script is that it cannot
>deal with data that is spanning more than 12 inodes (those were usually
>not in one block but fragmented over the harddisk). A line like this
>shows such a trickier example:
>
>99526  0 100644 6761321/1027 Sat Feb  2 09:11:58 2002
>
>I don't by hard know what to do with it, but it is laid out in the ext2
>undeletion how-to.


well, the undeletion howto is a little old (1999) but interesting to look
through...


http://tldp.org/HOWTO/Ext2fs-Undeletion.html#toc9


>
>> to bring this more on topic, i would like to see what ways something like
>> this can be improved- it served useful to me in the past, but i'm sure it
>> can be made more useful:::
>>
>>
>> #!/usr/bin/perl
>>
>> # added proper things when retyping it:
>> use warnings;
>> use diagnostics;
>> use strict;
>> #---
>>
>> my $cfile = "/tmp/commands.file";
>> my $filesystem ="/dev/hda6";
>> my @path = ("/tmp/recover","","/recover","",".ebu");  #making a path to
>put
>> my $date="Oct";  #just files from October#stuff later
>>
>> open (OUT,">$cfile");
>> print OUT "open $filesystem\n";# i wonder what this is for?
>
>Debug message?
>

no!  :)   debugfs -f /filepath  :)  open opens the filesystem without
mounting it... then dump does its thing- all inside debugfs!!


>
>command.file is the list of dump directives. It's supposedly a shell
>script that you can run later. So the above Perl script just generates
>another script. I am just not sure about
>
>> print OUT "open $filesystem\n";
>
>open /dev/hda6
>
>is not a meaningful command in shell scripts AFAIK.


and the mystery is solved!!!


now i would like to look into using this to make a perl script to automate
file recovery well, someday at anyrate!

willy

:)


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



RE: xor - i just don't understand *sigh*

2003-07-29 Thread West, William M
from Gary Stainburn:

>> print "xor1" if ($a = $a) ^ ($b = $c);
>
>Presumably this is because you're using the assignment operator and not the
>comparison operator.
>
>print "xor1" if ($a == $b) ^ ($b == $c);

interesting.. a '=' seems to work fine in an 'and' or 'or' statement--

using 'xor' in place of '^' seems to work also--- another response by
John W. Krahn [EMAIL PROTECTED] ::

>At the bit level
>they work the same as the example above.

(referering to using "and" "or" "xor" vs "&" "|" "^" etc...)

>  If you use them on numbers or
>strings they modify each bit of the number or string according to the
>example above.

>perldoc perlop


i will have to go over this documentation more thoroughly, i can now use the
tool- but understanding it is another thing entirely.  

thanks much  :)

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



RE: a hash reference is not a hash-> lesson learned the hard way. ..

2003-07-29 Thread West, William M
>> just want to share with other unwary folk the pitfalls
>> of making an assumption about perl (or anything for that matter)
>>
>>
>
>You are definitely correct a hash reference is not a hash, its a reference
>:-). Specifically to a hash
>
>>
>> i tried for the longest time to get something like
>> the following to work::
>>
>> foreach $section (keys %board){
>>
>
>First indication of ill effects is that you are looping over a list and
>setting your control variable, but then never using it. There are plenty of
>times when this will be needed but it appears in this case it may have hurt
>you not to

in that case, i was using the foreach atatement to let me expand on my code
later at this point i didn't need it


>
>> for my $a (1..19){
>> for (1..19){
>> $board->{"Q1S1"}->[$a]->[$_] and print "\n$a$_";
>
>Is the first key above where you are needing your control variable or is it
>something completely different?

just an option to expand the code :)


>> if i got rid of the "foreach $section (keys %board){"
>> the rest would work fine.  I was about to yell at you guys about it
>> when, out of desperation, i tried one last thing :
>>
>> my $board = \%board; #first line in the whole thing
>>
>> and it WORKS
>>
>
>Good guess, but like you said you need to know why this works...
>
>>
>> It turns out that a reference to a hash that's created on the 'spur of
>> the moment' and not explicitly made to refer to a %HASH doesn't work
>> the same way as a real hash :P
>>
>
>huh? I think I am misunderstanding what you mean, a hash reference is a
>hash reference is a hash reference...

it was an error in my logic- i was using a hash reference as if it were a
hash (i do not always write as clearly as i should *laugh*)

if i start using $board as a hash reference without a %hash assigned to it-
then that foreach statement above .. " foreach $section (keys %board)"
wouldn't work -- i had to creat %board first!  it took me forever to get
that through my head!

>
>> now that i've figured this out, i would love to learn a bit about
>> /how/ this works.
>>
>
>Here are four very well priced places to start:
>
>perldoc perlreftut
>perldoc perlref
>perldoc perllol
>perldoc perldsc
>

i have not yet looked at these docs- but will shortly :)

>
>>
>> btw- i know it looks like nonsense code, but i cut out some
>> details in the cut and paste *shrug*  - just testing some functions on
>> an individual basis.
>>
>>
>
>Good way to work, though for the purposes of this list it is often
>difficult to tell what you were doing/trying if the right amount of code is
>not presented. Though you seem to have grasped that concept well
>

i've found that it's the only way for me to proceed effectively- even while
i try to document code for myself, if i leave a peice alone, i have to spend
time re-familiarizing myself with it- testing functions entirely separately
/keeps/ my code strongly compartmentalized and makes life so much easier.

--- learned /that/ the hard way too!

thank you so much by the way!

willy


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



xor - i just don't understand *sigh*

2003-07-28 Thread West, William M
#!/usr/bin/perl -w

use strict;
use diagnostics;


my $a = 1;
my $b = 2;
my $c = 2;
my $d;

print "xor1" if ($a = $a) ^ ($b = $c);#prints

print "xor2" if ($a = $b) ^ ($b = $c);#no print

print "xor3" if ($a = $b) xor ($b = $c);#no print

print "xor4" if ($a = $a) xor ($b = $c);#no prints

print "xor5" if $a xor $b;#no prints

print "xor6" if $a xor $d;#prints


# so --- how do i use xor and ^ ???   i'd like to use it
# for statements like the first few *sigh*
#
# i don't understand why the first one prints i really
# need clarification on this one!
#
#

thanks  :)


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


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



a hash reference is not a hash-> lesson learned the hard way...

2003-07-23 Thread West, William M
just want to share with other unwary folk the pitfalls
of making an assumption about perl (or anything for that matter)



i tried for the longest time to get something like
the following to work::

foreach $section (keys %board){

for my $a (1..19){
for (1..19){
$board->{"Q1S1"}->[$a]->[$_] and print "\n$a$_";
$board->{"Q1S2"}->[$a]->[$_] and print "\n$a$_";
$board->{"Q2S1"}->[$a]->[$_] and print "\n$a$_";
$board->{"Q2S2"}->[$a]->[$_] and print "\n$a$_";
$board->{"Q3S1"}->[$a]->[$_] and print "\n$a$_";
$board->{"Q3S2"}->[$a]->[$_] and print "\n$a$_";
$board->{"Q4S1"}->[$a]->[$_] and print "\n$a$_";
$board->{"Q4S2"}->[$a]->[$_] and print "\n$a$_";
}
}
}


well, it is supposed to repeat the inner loops several times over right?
for each hashkey, do the following etc etc..

if i got rid of the "foreach $section (keys %board){"
the rest would work fine.  I was about to yell at you guys about it
when, out of desperation, i tried one last thing :

my $board = \%board; #first line in the whole thing

and it WORKS


It turns out that a reference to a hash that's created on the 'spur of
the moment' and not explicitly made to refer to a %HASH doesn't work
the same way as a real hash :P

now that i've figured this out, i would love to learn a bit about
/how/ this works.

$board ->{"blah"}  is different from $board = \%board; $board->{"blah"}

i think i understand, but would like a clear explanation anyway.


btw- i know it looks like nonsense code, but i cut out some
details in the cut and paste *shrug*  - just testing some functions on
an individual basis.



thanks,
willy

:)
  

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



scope of variable carrying 'for ($n1..$n2){}'

2003-07-23 Thread West, William M
for (1..19){
for (1..19){
print $_
}}

prints out the numbers 1 to 19 nineteen times...


just curious how to access the outer forloop's variable from
inside





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


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



Backup utility (was RE: concatonate to file?)

2003-06-16 Thread West, William M

#!/usr/bin/perl -w

#simple tar archiver... something to make a cron job with
#in the future :)


#thanks for the info for strftime :)  now can parse system time and
#use it
use POSIX qw(strftime);

# still unclear about '-w' verses 'use warnings'
use strict;
use diagnostics;

# where to put the archive::
my $targetpath = "/tmp/databackup";
#for timstamping filename:
my $date = strftime("%A %B %C", localtime time);
# files to archive:
my $files = "/home/willy/tmp";

#parse the date information from strftime-- takes the data and
#removes the spaces
#$date=~ s/^(\S*\s\S*\s\S*).*/$1/s;
#the above is no longer needed- was going to use 'date' untill Robin
#Norwood set me straight :)
#
$date=~ s/\s//g;

#concatonate (thanks to rob and tim)
$targetpath = $targetpath.$date.".bak";

print "path = $targetpath\n"; #debug


#make the archive:
`tar -cvzf $targetpath $files`;


#thank you all :)
#willy


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



concatonate to file?

2003-06-16 Thread West, William M

i'd like to take a couple of strings to concatonate to a path...

here's my start the code:::

#!/usr/bin/perl -w


use strict;
use diagnostics;

my $date = `date`; #not sure about redirecting output to $path!

$date=~s/( ){3}/; #i think this is proper to just take the string
#up to the third whitespace character...

my $filename = append_date_to_rest_of_filename();



#the end :)


-
willy
http://www.hackswell.com/corenth 


thanks :)


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