Re: Reading file line by line regardless of type of end-of-line?
[EMAIL PROTECTED] wrote: > > > Michael Fowler <[EMAIL PROTECTED]> said: > > > You left out the Macintosh EOL sequence, , and I don't know > > what uses simply as EOL. > > Macs use just . No machine that I know of uses as a line > terminator. I don't know this from experience, but I remember hearing that Amigas used as their line terminator. It's a piece of trivia that's been floating about in my brain now for about 12 years which I've never had reason to test, discard or even care about. Is someone else in a position to tell me the rights and wrongs of this? and how closely this is related to perl! the moderators probably have their fingers poised over the key...ank Arthur N. Klassen, the quote.jester -- ansak| +t+ -> | |@ !! |b i g f o o t.c o m |PGP:30DF 376C 43D0 DA74 F33F At home in the darkness but hungry for dawn... |752C 192E 3711 5E52 02BF "One never can see... why any one was selected for any job. And when one does, it is usually for some reason that leaves no room for vanity.".csl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Cannot read/write to an output log.
Hi, If $date is present in my log then I want to add something to the end of the same line. If it is not present I want to insert the date on a new line and add stuff to the end. If present, $date will always be in the last line of the log. I have tried all kinds of things, but I cannot get it to work properly. The print statements are not being executed. I believe the below code to be the most correct what I have come up with so far. Perl -w does not give an error that the log is not yet open. That seems to be okay. See below for the format of the output log. What I am doing wrong here? ### begin code snippet ### open (LOGFILE, "+>>$resultlog") || die "cannot open $resultlog\n"; while () { if (/$date/) { print "date found: script has run before today\n"; measurement (); print LOGFILE ("\t", "$hour:$min", "\t", "$bandwith"); } # end if. else { print "date not found: inserting date\n"; measurement (); print LOGFILE ("\n", "$date", "\t", "$hour:$min", "\t", "$bandwith"); } # end else. } # end while. close (LOGFILE); ### end code snippet ### Sample output log: 2001-08-03 10:23 4,5615:14 5,0121:45 6,21 2001-08-04 10:23 3,9815:15 1,2121:45 6,18 2001-08-05 10:23 4,14 In this example $date would be 2001-08-05 Thanks in advance, Louis. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: If Statement won't work
By any chance are you using Activestate? I have no explanation, but I have run across two or three times when everything should have worked, the variable evalueated to what it should have been, but the if refused to return true and execute. those three times I have been able to delete the line and re-type it and make it work. Like I said, I have no explanation as to why, but yes I have run into times when the if just refused to work. I just happen to use activestate which is why I asked the first question. I'd like to see if there is some common denominator between what we have seen in this. Steve H. >From: [EMAIL PROTECTED] >To: [EMAIL PROTECTED] >Subject: If Statement won't work >Date: Thu, 2 Aug 2001 11:22:25 -0500 > >Can anyone tell me why my if statement refuses to work? It is really >simple. I can't understand it. > >$winner = 1; >if($winner == 1){ >print "$winner\n"; >} > >No matter what I try, it never returns true. Not even 1 == 1. > >Any ideas? > >Chris >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] _ Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Some Extremely Clueless Questions!
> On Sunday 05 August 2001 8:01 am, [EMAIL PROTECTED] wrote: >> Hello, >> 1) How exactly do I edit a script? In Word and then change it to a .pl >> file? Do I have to change file types back and forth every time I change >> the script? >> A program that I found quite useful for writing and editing perl scripts is NOTETAB: a text-editor which has a freeware version and supports built-in libraries (which are customizable!), amongst which are some for writing and debugging perl. More info at http://www.notetab.com. Birgit -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: If Statement won't work
That is it. I downloaded activestate to play with. I'm glad that I am not loosing my mind and that someone else had this problem too. Thanks for putting me at ease. Chris At 09:51 AM 8/5/2001, Steve Howard wrote: >By any chance are you using Activestate? I have no explanation, but I have >run across two or three times when everything should have worked, the >variable evalueated to what it should have been, but the if refused to >return true and execute. those three times I have been able to delete the >line and re-type it and make it work. > >Like I said, I have no explanation as to why, but yes I have run into times >when the if just refused to work. I just happen to use activestate which is >why I asked the first question. I'd like to see if there is some common >denominator between what we have seen in this. > >Steve H. > > >From: [EMAIL PROTECTED] > >To: [EMAIL PROTECTED] > >Subject: If Statement won't work > >Date: Thu, 2 Aug 2001 11:22:25 -0500 > > > >Can anyone tell me why my if statement refuses to work? It is really > >simple. I can't understand it. > > > >$winner = 1; > >if($winner == 1){ > >print "$winner\n"; > >} > > > >No matter what I try, it never returns true. Not even 1 == 1. > > > >Any ideas? > > > >Chris > >-- > >To unsubscribe, e-mail: [EMAIL PROTECTED] > >For additional commands, e-mail: [EMAIL PROTECTED] > > >_ >Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp > > >-- >To unsubscribe, e-mail: [EMAIL PROTECTED] >For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
passing values to sub
I have two files called html.pl and config.pl, both of which require each other. in html.pl, a subroutine starts like this: my (@hits) = @_; my ($numhits) = ($#hits+1) / ($#db_cols+1); my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = $db_max_hits); &html_record; The subroutine &html_record is contained in the other file, config.pl. I want to make the array @hits as well as the values of $numhits and $maxhits available to that sub. I know that it works when I "de-privatize" the variables, i.e. remove the "my" and the parentheses from the above code. But I don't understand enough of perl to figure out (a) whether this is a good idea memory-, speed- & style-wise and (b) whether there might be a different way. Note that I won't be needing the variable values anymore in other subs in html.pl (which, er, is why they were originally declared as private variables). Many thanks in advance, Birgit Kellner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Breaking out of foreach loop
Sorry if this is a repost. Sent it from wrong address. Can someone tell me how I can break out of a foreach loop before the end? Thanks Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: passing values to sub
On Sun, Aug 05, 2001 at 07:27:25PM +0200, Birgit Kellner wrote: > I have two files called html.pl and config.pl, both of which require each > other. > > The subroutine &html_record is contained in the other file, config.pl. I > want to make the array @hits as well as the values of $numhits and $maxhits > available to that sub. I know that it works when I "de-privatize" the > variables, i.e. remove the "my" and the parentheses from the above code. > But I don't understand enough of perl to figure out (a) whether this is a > good idea memory-, speed- & style-wise and (b) whether there might be a > different way. Note that I won't be needing the variable values anymore in > other subs in html.pl (which, er, is why they were originally declared as > private variables). Global variables are rarely a good idea. In this case it just sounds as though you need to be passing parameters around. > in html.pl, a subroutine starts like this: > my (@hits) = @_; > my ($numhits) = ($#hits+1) / ($#db_cols+1); There is no need for parentheses around $numhits. my $numhits = ($#hits+1) / ($#db_cols+1); > my ($maxhits); $in{'mh'} ? ($maxhits = $in{'mh'}) : ($maxhits = > $db_max_hits); This equivalent line is much simpler I think. No need for the quotes around 'mh' or for ?: my $maxhits = $in{mh} || $db_max_hits; > &html_record; No need for the &, and pass the parameters. html_record($numhits, $maxhits, @hits); If @hits is large you might want to pass it around by reference. You might also like to consider whether %in should be global. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Breaking out of foreach loop
Can someone tell me how I can break out of a foreach loop before the end? Thanks Chris -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Random Number Generation
On Sun, Aug 05, 2001 at 07:31:45AM -1000, . wrote: > > Before 5.004 you did need to seed the PRNG, but I'm not convinced that > > time|$$ was ever a really good choice. Good enough for most purposes > > though, if called only once. > > But why only once? That's the part that confusses me. I think this has been explained well by Gary Stainburn. > > > But this only produces a psedo random number. Thus only a subset of the > > > possible numbers will ever be invoked, and in a certain sequence at > that. > > > > Well, that depends on how good your PRNG is. And the sequence depends > > on the seed you choose. I suspect that in general, perl will choose a > > better seed than you, but check out pp.c if you want to see the gory > > details. > > Where do I find it? In the perldocs/manpages someplace? pp.c is a part of the Perl source code. > > Are pseudo random numbers not good enough for you? What do you want to > > do - high grade crytography? > > No, but giving it some arbitrary integer range isn't sufficient, either > since only a fraction of the numbers would ever get used. Here's an example > of what I'm doing with this (pseudocode): > > done = false > while !done { > number = random_number > if number is not in set_of_numbers { > add number to set_of_numbers > done = true > } > } > > So what happens if the PRNG starts repeating values? Like what would happen > pretty quickly with: > > rand 100 > > It get's caught in an infinite loop. If you re-seed each pass through the > loop, then the only way it will get caught is if all possible numbers are > taken. It might get a little slow once most of the numbers have been taken, > but it won't get stuck that way. That is, unless you're using another PRNG > to seed it, say with: > > rand(rand*100) > > In fact, both mathematically and from my own experience, this will have the > effect of reducing the randomness of the number gereration. Hence, time is > an efficient seed because it's constantly changing in a way that's > theoretically impossible to repeat. (Unless you know of a way to make a > computer's internal clock start to move backwards w/o adversely affecting > the system. :) OK. You are getting very confused and making this an awful lot harder than it needs to be. A PRNG *will* repeat values. If 100 calls to int rand(100) produced the numbers 0-99 then it wouldn't be very random. The PRNG will not get caught in an infinite loop. At least not for a very long time if it is any good. You shouldn't re-seed it. A lot of clever people have arranged things such that it is very easy to get reasonable random numbers for general use. Don't subvert their work unless you know what you are doing and why. Try this: #!/usr/bin/perl print int rand 100, "\n" while 1; __END__ Look at the output and tell us how long it takes for the pattern to repeat. That should kill this thread for a while ;-) -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Breaking out of foreach loop
for (1..10) { last if /3/; print; } you'll notice this printing '12' so 'last' breaks out of the loop if the condition is met hth Jos Boumans - Original Message - From: "Webmaster" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Sunday, August 05, 2001 7:31 PM Subject: Breaking out of foreach loop > Can someone tell me how I can break out of a foreach loop before the end? > > Thanks > > Chris > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Random Number Generation
Thanks for the info. Aziz,,, In article <[EMAIL PROTECTED]>, "smoot" <[EMAIL PROTECTED]> wrote: >> "Abdulaziz Ghuloum" <[EMAIL PROTECTED]> said: > >> Doesn't /dev/random produce pseudo-random numbers also? What makes >> reading from it better than using perl's rand or C's rand? > > This is getting a bit of topic. > > /dev/random is seeded with supposedly random events. In Linux I believe > it takes the time between keyboard and mouse events and builds up an > entropy base. The better the entropy base, the more random the bits > from /dev/random are. ... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: passing values to sub
--On Sonntag, 05. August 2001 19:51 +0200 Paul Johnson <[EMAIL PROTECTED]> wrote: > On Sun, Aug 05, 2001 at 07:27:25PM +0200, Birgit Kellner wrote: >> I have two files called html.pl and config.pl, both of which require >> each other. >> >> The subroutine &html_record is contained in the other file, config.pl. I >> want to make the array @hits as well as the values of $numhits and >> $maxhits available to that sub. I know that it works when I >> "de-privatize" the variables, i.e. remove the "my" and the parentheses >> from the above code. But I don't understand enough of perl to figure >> out (a) whether this is a good idea memory-, speed- & style-wise and >> (b) whether there might be a different way. Note that I won't be >> needing the variable values anymore in other subs in html.pl (which, >> er, is why they were originally declared as private variables). > >> in html.pl, a subroutine starts like this: >> my (@hits) = @_; >> my ($numhits) = ($#hits+1) / ($#db_cols+1); > > There is no need for parentheses around $numhits. Thank you very much for cleaning up my code. > html_record($numhits, $maxhits, @hits); > I had figured that much, but got stuck on the other end: The sub in the second file, config.pl, does not get these values. With my @hits = @_; I get the content of @hits all right, but how do I get $numhits and $maxhits? Birgit Kellner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: passing values to sub
On Sun, Aug 05, 2001 at 10:15:09PM +0200, Birgit Kellner wrote: > --On Sonntag, 05. August 2001 19:51 +0200 Paul Johnson <[EMAIL PROTECTED]> > wrote: > > > html_record($numhits, $maxhits, @hits); > > > I had figured that much, but got stuck on the other end: The sub in the > second file, config.pl, does not get these values. With > my @hits = @_; > I get the content of @hits all right, but how do I get $numhits and > $maxhits? sub sonic { my ($numhits, $maxhits, @hits) = @_; ... } -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: passing values to sub
I'm just a beginnner BUT why not use HashRef for the @hits array to make all data going to sub sonic a scalar values Then sub sonic would be... sub sonic { my ($numhits, $maxhits, $hits) = @_; ... } YOu would just need to deference the reference. MIke -Original Message- From: Paul Johnson Sent: Sun 8/5/2001 4:33 PM To: Birgit Kellner Cc: [EMAIL PROTECTED] Subject: Re: passing values to sub On Sun, Aug 05, 2001 at 10:15:09PM +0200, Birgit Kellner wrote: > --On Sonntag, 05. August 2001 19:51 +0200 Paul Johnson <[EMAIL PROTECTED]> > wrote: > > > html_record($numhits, $maxhits, @hits); > > > I had figured that much, but got stuck on the other end: The sub in the > second file, config.pl, does not get these values. With > my @hits = @_; > I get the content of @hits all right, but how do I get $numhits and > $maxhits? sub sonic { my ($numhits, $maxhits, @hits) = @_; ... } -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: passing values to sub
--On Sonntag, 05. August 2001 22:33 +0200 Paul Johnson <[EMAIL PROTECTED]> wrote: > > sub sonic > { > my ($numhits, $maxhits, @hits) = @_; > ... > } > sub genius { print "thank you"; } Birgit Kellner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: passing values to sub
On Sun, Aug 05, 2001 at 04:39:44PM -0400, Mike Rapuano wrote: > I'm just a beginnner BUT why not use HashRef for the @hits array to make > all data going to sub sonic a scalar values > > Then sub sonic would be... > > sub sonic > { > my ($numhits, $maxhits, $hits) = @_; > ... > } Certainly. I mentioned that possibility in my first message, and this is especially useful if @hits is big. It would be an array reference of course rather than a hash reference. > YOu would just need to deference the reference. Quite. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: passing values to sub
On Sun, Aug 05, 2001 at 10:38:21PM +0200, Birgit Kellner wrote: > > > --On Sonntag, 05. August 2001 22:33 +0200 Paul Johnson <[EMAIL PROTECTED]> > wrote: > > > > > sub sonic > > { > > my ($numhits, $maxhits, @hits) = @_; > > ... > > } > > > sub genius { > print "thank you"; > } Nah. I just happen to have written quite a few subroutines over the years. I'm sure it takes a bit more than that to earn that accolade. There are a number people working with Perl who are right up there though. But thanks anyway. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: passing values to sub
Actualy, what you did is not a hash, but three scalars - and yes, that would work. To use a hash SLICE local to the subroutine, you would do it like this: sub sonic { my %lh; @lh{qw(numhits maxhits hits)} = @_; ... } After that, you could refer to the values locally as: $lh{numhits} $lh{maxhits} and $lh{hits} Just a note. Your method would work, but it was not a hash. Steve H. -Original Message- From: Mike Rapuano [mailto:[EMAIL PROTECTED]] Sent: Sunday, August 05, 2001 3:40 PM To: Paul Johnson; Birgit Kellner Cc: [EMAIL PROTECTED] Subject: RE: passing values to sub I'm just a beginnner BUT why not use HashRef for the @hits array to make all data going to sub sonic a scalar values Then sub sonic would be... sub sonic { my ($numhits, $maxhits, $hits) = @_; ... } YOu would just need to deference the reference. MIke -Original Message- From: Paul Johnson Sent: Sun 8/5/2001 4:33 PM To: Birgit Kellner Cc: [EMAIL PROTECTED] Subject: Re: passing values to sub On Sun, Aug 05, 2001 at 10:15:09PM +0200, Birgit Kellner wrote: > --On Sonntag, 05. August 2001 19:51 +0200 Paul Johnson <[EMAIL PROTECTED]> > wrote: > > > html_record($numhits, $maxhits, @hits); > > > I had figured that much, but got stuck on the other end: The sub in the > second file, config.pl, does not get these values. With > my @hits = @_; > I get the content of @hits all right, but how do I get $numhits and > $maxhits? sub sonic { my ($numhits, $maxhits, @hits) = @_; ... } -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Question regarding ( ) s
When calling a built in Perl function such my, print or open is it convention to only use ( ) s when the context calls for it, or is it better for consistency to just go ahead and always pass params to a function as a list?
RE: Some Extremely Clueless Questions!
Hello: Your questions are not necessarily clueless. I had to do a lot of digging to find out the information detailed below. And before someone screams RTFM, I'll continue... Don't use Word. Go here http://www.perlmonks.org/index.pl?node=Outside%20Links and download a few editors and pick one that you like. You can always execute a script by calling the Perl interpreter with the script as an argument: e.g., perl pscript.pl. You can also associate files with a .pl extension with the Perl interpreter, so that executing pscript.pl will correctly invoke the Perl interpreter and execute your script. The following commands (performed at the DOS prompt) will let you do this: assoc .pl=Perl ftype Perl=c:\Perl\Bin\Perl.exe %1 %* This assumes, of course, that Perl has been installed on your C: drive. If not, then use whatever path is applicable. To avoid having to type in the extension (.pl) every time you execute a script, you can set the PATHEXT environment variable to include Perl scripts. This is done through the following command: set pathext=%pathext%;.pl On another topic, I strongly suggest buying the following books (these have been a life-saver for me): Learning Perl on Win32 Systems (a 3rd edition has come out, which incorporates both UNIX and Win32, but I haven't had time to evaluate it yet, so I can't recommend it; however, since it's an O'Reilly book, it's probably to be preferred over Learning Perl on Win32 Systems). Win32 Perl Programming: The Standard Extensions. By Dave Roth. Win32 Perl Scripting: The Administrator's Handbook. Also by Dave Roth. Programming Perl (3rd Edition). By Wall, Christiansen, & Orwant. Go to www.bookpool.com to order any of these at cut rate prices. Anyway, I hope this helped you out. Dean Theophilou Genisar -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Sunday, August 05, 2001 12:01 AM To: [EMAIL PROTECTED] Subject: Some Extremely Clueless Questions! Hello, I'm learning Perl for work, where the OS is Unix, but I'd like to practice at home, where I'm using Windows 95. I downloaded and installed ActivePerl, but can't get anything whatsoever to run, including the example script that came with ActivePerl. My questions at this point: 1) How exactly do I edit a script? In Word and then change it to a .pl file? Do I have to change file types back and forth every time I change the script? 2) How do I add the path to the Perl program to MS-DOS? Thanks in advance for your help. Leonard -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Question regarding ( ) s
On Sun, Aug 05, 2001 at 05:02:25PM -0400, Brett wrote: > When calling a built in Perl function such my, print or open is > it convention to only use ( ) s when the context calls for it, > or is it better for consistency to just go ahead and always > pass params to a function as a list? Well, first, "my" isn't a function. Is the reason that so many people write my ($x) = 1; because people think it is? H. But on to your question. Have you looked at perlstyle? · Omit redundant punctuation as long as clarity doesn't suffer. ... Along the same lines, just because you CAN omit parentheses in many places doesn't mean that you ought to: return print reverse sort num values %array; return print(reverse(sort num (values(%array; When in doubt, parenthesize. At the very least it will let some poor schmuck bounce on the % key in vi. Even if you aren't in doubt, consider the mental welfare of the person who has to maintain the code after you, and who will probably put parentheses in the wrong place. I like the first point. I have looked at code with redundant punctuation trying to work out the hidden gotcha that necessitated the punctuation. Leave it out if you can reasonably do so. -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Parsing a File
I'm looking for pointers on what to do next. I have a file (the output from 'show cdp neighbors detailed' on a Cisco router. I created a short program which captures the output to a file - looks something like this... CDP log for ca5gw001.winstar.com Created: 22:00:29 - 2001/08/01 - Device ID: ca5gw002.winstar.com Entry address(es): IP address: 10.1.25.3 Platform: cisco 4700, Capabilities: Router Interface: Ethernet3/0, Port ID (outgoing port): Ethernet0 Holdtime : 167 sec Version : Cisco Internetwork Operating System Software IOS (tm) 4500 Software (C4500-JS-M), Version 11.3(7), RELEASE SOFTWARE (fc1) Copyright (c) 1986-1998 by cisco Systems, Inc. Compiled Tue 01-Dec-98 17:26 by kpma - Device ID: ca24gw001.winstar.com Entry address(es): IP address: 10.0.252.141 Platform: cisco 2610, Capabilities: Router Interface: Serial2/2, Port ID (outgoing port): Serial0/0 Holdtime : 156 sec ... The first two lines are created during the capture and I hope to use them as some sort of an ID. Now I'd like to pull some key information from this file and set up a table. I figured out how to read the file as a single string, strip the newlines and double spaces and then split on the '-' so I can now address each record as part of an array. Here is $B[1]: Device ID: wa2gw001.winstar.com Entry address(es): IP address: 10.0.249.117 Platform: cisco 7206VXR, Capabilities: Router Interface: Hssi11/1/0.174, Port ID (outgoing port): Serial2/2.105 Holdtime : 121 sec Version : Cisco Internetwork Operating System Software IOS (tm) 7200 Software (C7200-IS-M), Version 12.0(7)T, RELEASE SOFTWARE (fc2) Copyright (c) 1986-1999 by cisco Systems, Inc. Compiled Tue 07-Dec-99 16:36 by phanguye advertisement version: 2 The next step would be to pull out the info without all the extraneous information. The output should eventually look something like (separated with tabs): ca5gw001E3/0ca5gw002E010.1.25.34700router 11.3(7), fc1 ca5gw001S2/2ca24gw001S0/010.0.252.1412610 router12.0(4)T, fc1 ... I'm not coming close to a general way to pull this information out of each array element. I figure I have to use regular expressions to match the info I want - maybe use $1, $2, $3... if I can figure out what to match. This post is long enough. If anyone's interested, I could post the code fragments I've come up with so far. I've got the Perl CD Bookshelf - just can't put it into practice yet. Thanks, Kevin -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Some Extremely Clueless Questions!
Dean, Thank you very much for your detailed advice, and thanks to everyone who offered advice. Very helpful. I have gotten this working and can now start asking clueless questions about Perl itself. :-) Len ** In a message dated 8/5/01 2:12:19 PM Pacific Daylight Time, [EMAIL PROTECTED] writes: > Your questions are not necessarily clueless. I had to do a lot of digging > to find out the information detailed below. And before someone screams > RTFM, I'll continue... -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Reading file line by line regardless of type of end-of-line?
At 07:11 AM 08/04/2001 -0700, Arthur Klassen wrote: >[EMAIL PROTECTED] wrote: >> >> > Michael Fowler <[EMAIL PROTECTED]> said: >> >> > You left out the Macintosh EOL sequence, , and I don't know >> > what uses simply as EOL. >> >> Macs use just . No machine that I know of uses as a line >> terminator. > >I don't know this from experience, but I remember hearing that Amigas used > as their line terminator. It's a piece of trivia that's been >floating about in my brain now for about 12 years which I've never had >reason to test, discard or even care about. Is someone else in a position to >tell me the rights and wrongs of this? Actually, the miggyOS was very Unix-like, and thus shared the same line terminator. IIRC, I actually installed the Amiga port of Perl, but never got around to using it (and /learning it) on that box...then again I never had a use for it, since AOS had that cool built-in ARexx interprocess scripting language (like Applescript). Ah, I sort of miss the good ol' days of the Video Toaster on my A2000 (souped up with a BLAZING Zeus 68040/28Mhz accelerator, of course ;)) Aloha, mel -- mel matsuokaHawaiian Image Productions Chief Executive Alphageek (vox)1.808.531.5474 [EMAIL PROTECTED] (fax)1.808.526.4040 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
isEmail function
Quick question, I have this isEmail function below. Should this cover the basis for verifying an email address or am i missing an possibility? # input : scalar # output: true or false sub isemail { my($val) = shift(@_); return 0 if (!defined($val)); return $val =~ / ^\w+(?:[\.-]?\w+)*@\w+(?:[\.-]?\w+)*(?:\.[a-zA-Z]{2,3}){1}$ | ^\w+(?:[\.-]?\w+)*@(?:\d{1,3}\.){3}(?:\d{1,3}){1}$ /x ? 1 : 0; }
Re: isEmail function
At 08:02 PM 08/05/2001 -0400, Brett wrote: >Quick question, I have this isEmail function below. Should this cover >the basis for verifying an email address or am i missing an possibility? > > ># input : scalar ># output: true or false >sub isemail { >my($val) = shift(@_); >return 0 if (!defined($val)); >return $val =~ / > ^\w+(?:[\.-]?\w+)*@\w+(?:[\.-]?\w+)*(?:\.[a-zA-Z]{2,3}){1}$ > | > ^\w+(?:[\.-]?\w+)*@(?:\d{1,3}\.){3}(?:\d{1,3}){1}$ > /x ? 1 : 0; >} Validating email addresses using regexps is really a futile exercise. It's, for all intents and purposes, impossible. Theres a regexp which was published in "Mastering Regular Expressions" which apparantly is as close as you can get, but the regexp itself is 6,859 bytes long! Most of this is covered in perlfaq(9). A better, more workable alternative would be to check for a valid MX record for the given domain name. Aloha, mel -- mel matsuokaHawaiian Image Productions Chief Executive Alphageek (vox)1.808.531.5474 [EMAIL PROTECTED] (fax)1.808.526.4040 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Some Extremely Clueless Questions!
>From the Activestate documentaion, here's a list editors: What editors are available for Windows? Windows comes with two editors that are great for editing Perl, NotePad and WordPad. But, if you need more features for ease of editing, here is a list of free and commercial editors: BBEdit - http://www.barebones.com/ A Macintosh editor that supports multiple languages including Perl. By adding Brad Hanson's BBEdit Plug-Ins you can run your Perl scripts right in BBEdit CodeWright - http://www.premia.com/ With Codewright, you choose the compiler, the assembler, the version control system--any tools you like--and Codewright works with you. Includes Perl language support. ED for Windows - http://www.getsoft.com/ ED leads the way in intelligent language sensitive editing. Supporting both DOS and Windows, ED is as easy to use as it is to spell. Up and running straight out of the box for the new user but highly configurable, ED fits the way YOU want to work. Includes support for Perl syntax highlighting. GNU Emacs for Windows - http://www.cs.washington.edu/homes/voelker/ntemacs.html "Emacs is the extensible, customizable, self-documenting real-time display editor." HomeSite - http://www.allaire.com HomeSite 4.0 is the award-winning HTML editing tool that lets you build great Web sites in less time, while maintaining Pure HTML. Good editor for ASP, and PerlScript. MultiEdit - http://www.amcyber.com/ MultiEdit is an multiple language editor. Perl language support includes - smart indenting, template editing, construct matching, code completion, context highlighting, brace/parenthesis alignment and line-numbering. Other MulitEdit features include multiple file search/replace, HTML and ASP support, web site management, integration with several IDEs and debuggers, and the ability to compare and sychronize files while editing. NoteTab - http://www.notetab.com Seamless support for Perl and Gawk scripts (only commercial versions). Perl Builder - http://www.solutionsoft.com/perl.htm Perl Builder is a complete, integrated development environment (IDE) for Perl. Whether you are an experienced Perl developer or a non-programmer who needs to create Perl CGI scripts, Perl Builder's visual tools are guaranteed to dramatically improve your productivity! Perl Builder is a 32-bit application and requires Windows 95 or NT. Perl Scripting Tool - PST was intended as a replacement for Windows' Notepad, which until now has been the editor of choice for Win32 PERL Programmers. While Notepad is usually sufficient there has long been the need for something with 'just a little more'. This simple editor is Notepad with a few extra options for PERL script authoring, including a subroutine library, code wizard, run, debug, syntax check, floating toolbox and more. An extremely simple and straight-forward PERL GUI. Programmer's File Editor (PFE) - http://www.lancs.ac.uk/people/cpaap/pfe/ PFE is a large-capacity, multi-file editor that runs on Windows 98, Windows 95, Windows NT 4.0 and Windows 2000 on Intel-compatible processors, and on Windows 3.1x. Although it's primarily oriented towards program developers and contains features like the ability to run compilers and development applications, it also makes a very good general purpose editor for any function at all. TextPad - http://www.textpad.com TextPad is a fully featured text editor for Windows. 16 and 32 bit editions available. UltraEdit - http://www.ultraedit.com/ UltraEdit is a disk based editor with a 16-Bit version for Windows 3.x and a 32-Bit version for Windows NT and Windows 95 (not Win32s). It includes bazillions of features including a Perl wordfile for Perl syntax highlighting. VIM - http://www.vim.org The "Vi IMproved" editor -- Now with Perl support. VIM provides Perl syntax highlighting, and a Perl interface. The Perl interface provides the ability to run a Perl command or run a Perl command for each line in a range. For more information on Perl support, see the Perl and VIM help page. VisualSlickEdit - http://www.slickedit.com Visual SlickEdit combines the richest set of powerful editing features with more configurability than any software product in any
Re: Some Extremely Clueless Questions!
It's the shebang that *I* have to change each time I upload a perl script from Windows to unix. What happens when you try to run a script? [EMAIL PROTECTED] wrote: > > Hello, > > I'm learning Perl for work, where the OS is Unix, but I'd like to practice at > home, where I'm using Windows 95. I downloaded and installed ActivePerl, but > can't get anything whatsoever to run, including the example script that came > with ActivePerl. My questions at this point: > > 1) How exactly do I edit a script? In Word and then change it to a .pl > file? Do I have to change file types back and forth every time I change the > script? > > 2) How do I add the path to the Perl program to MS-DOS? > > Thanks in advance for your help. > > Leonard > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] -- New IRC network dedicated to democracy. http://www.afreeirc.net/ irc.AFreeIRC.Net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Perl Scripts for GAIM
Hey everyone - Sorry to repost this, but I'm afraid it might have been overlooked. I recently switched from windows to linux (Mandrake 8.0), and I noticed while using GAIM that there is an option in the Tools menu to load Perl scripts. Are there any sites that offer any tutorials on writing scripts with Perl for GAIM? I really would like to know what sort of applications are possible with this plugin for GAIM. I searched google, and found some tutorials at webreference.com and mit, but they were a little over my head, as I am an extreme newbie to Perl (most of my programming experience has been with PHP and JavaScript). I'd be grateful if anyone could help me out. TIA Tom Malone -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Some Extremely Clueless Questions!
--On Sonntag, 05. August 2001 21:03 -0400 Bompa <[EMAIL PROTECTED]> wrote: > > NoteTab - http://www.notetab.com > Seamless support for Perl and Gawk scripts (only commercial > versions). Just for the record: this used to be true for earlier versions of NoteTab. Current releases have Perl and Gawk support built in also in the freeware version. birgit kellner -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: If Statement won't work
On Sun, Aug 05, 2001 at 09:51:15AM -0500, Steve Howard wrote: > By any chance are you using Activestate? I have no explanation, but I have > run across two or three times when everything should have worked, the > variable evalueated to what it should have been, but the if refused to > return true and execute. those three times I have been able to delete the > line and re-type it and make it work. This sounds suspiciously like your editor inserted invisible characters where it shouldn't have. Have you ever tested such code with any other perl, such as cygwin's, or one on a Unix box? Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Cannot read/write to an output log.
On Sun, Aug 05, 2001 at 12:56:47PM +0200, Louis wrote: > Hi, > > If $date is present in my log then I want to add something to the end of > the same line. If it is not present I want to insert the date on a new line > and add stuff to the end. If present, $date will always be in the last line > of the log. See perldoc -q 'in a file'. For one thing, you can't mix reading and writing like this without getting strange results in your file (unless the file is of a very specific format). For another, the mode "+>>" sets the file position to the end of the file, which is almost certainly not what you intended, because you're reading from the file. Also, the mode "+>>" means all writes are to the end of the file, regardless of where the current file position is. > ### begin code snippet ### > > open (LOGFILE, "+>>$resultlog") || die "cannot open $resultlog\n"; [snip] Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Checking for letters and spaces in regular expression??
Hi everyone, Given the following code why does it print out "Valid chars in string."? In other words why does the space between "San" and "Jose" not make the if expression true? my $string = "San Jose"; if ($string !~ /[a-zA-Z]/) { print "Invalid characters in string." } else { print "Valid chars in string." } Thanks. -- Carlos www.internetsuccess.ca -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: If Statement won't work
I did not test it on another Perl installation. However, I did go through even to the end of the line and try to find an invisible white space, or anything that might have changed it. I even changed editors to see if there was something I could see in one that I couldn't in the other. Like I said, I made it work by deleting the line and re-typing it, but when this message popped up on this list, I knew someone other than just me had seen this problem and I decided to see if I could find any common thread between what I had seen, and the problem this person was having. Steve H. -Original Message- From: Michael Fowler [mailto:[EMAIL PROTECTED]] Sent: Sunday, August 05, 2001 10:02 PM To: Steve Howard Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Re: If Statement won't work On Sun, Aug 05, 2001 at 09:51:15AM -0500, Steve Howard wrote: > By any chance are you using Activestate? I have no explanation, but I have > run across two or three times when everything should have worked, the > variable evalueated to what it should have been, but the if refused to > return true and execute. those three times I have been able to delete the > line and re-type it and make it work. This sounds suspiciously like your editor inserted invisible characters where it shouldn't have. Have you ever tested such code with any other perl, such as cygwin's, or one on a Unix box? Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Executing the kill command from within an suid script.
Hi I would like to run an suid perl script that among other things sends a kill -USR1 signal to a process. I have read about Perl tainting variables for security etc and to write a .c wrapper. I did this but still get an error running system() calls from within my perl script. I changed the system call to do a fork and then exec the kill in the child but this still errors with the statement : Insecure dependency in exec while running setuid at . The C executable is setuid but the perl script is not. Basically the process I wish to send a kill signal to is a redirector for squid. The process is owned by the squid user. The kill signal makes the redirector dump statistics about itself to a file. I want to run a script from my cgi-bin which will run as user nobody that can send the kill signal to the process that squid owns. The script works fine when run as root. Does anyone know how I can get my perl script to run as another user and issue a kill signal to a process? Thankyou. *** This email and any files transmitted with it, are confidential and is intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error, please notify the system manager. This footnote also confirms that this email message has been scanned by AUSTAR Communications content and virus scanning applications for the presence of computer viruses. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Checking for letters and spaces in regular expression??
On Sun, Aug 05, 2001 at 09:44:00PM -0600, Carlos C.Gonzalez wrote: > Hi everyone, > > Given the following code why does it print out "Valid chars in string."? > In other words why does the space between "San" and "Jose" not make the > if expression true? You are reversing the sense of the test with !~. It's effectively "!$string =~ /[a-zA-Z]", meaning the test will only evaluate to true if there are no [a-zA-Z] characters in the string. "San Jose" has 7 such characters. If you are trying to verify the string has non-alphabetic characters, you should say: if ($string =~ /[^a-zA-Z]/) { print "Invalid characters ..." } else { ... } > my $string = "San Jose"; > > if ($string !~ /[a-zA-Z]/) { > print "Invalid characters in string." > } > else { > print "Valid chars in string." > } Michael -- Administrator www.shoebox.net Programmer, System Administrator www.gallanttech.com -- -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
split problem
Hello! What's the problem with my split? $line = "var=value"; ($var, $value) = split(/\s*[=]\s*/, $line); Krisztian I experienced that $var and $value contained the first letter of the var and the value. Sometimes nothing. Where is the error? Krisztian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: split problem
> What's the problem with my split? > > $line = "var=value"; > ($var, $value) = split(/\s*[=]\s*/, $line); Looks fine to me. > I experienced that $var and $value contained the first letter of the var and > the value. Sometimes nothing. Where is the error? Looks to me like it must be in your input. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: split problem
On 8/5/01 9:39 PM, Romek Krisztián wrote: > Hello! > > What's the problem with my split? > > $line = "var=value"; > ($var, $value) = split(/\s*[=]\s*/, $line); > > Krisztian > > I experienced that $var and $value contained the first letter of the var and > the value. Sometimes nothing. Where is the error? > > Krisztian > Your syntax is fine, and the split works just as it should. $var gets set to "var" and $value gets set to "value". (The variables and strings with the same names might be causing some confusion, though.) -Michael Kelly Email: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Can I post through a regular newsreader?
Hi everyone, I just got an answer to a post from Michael (thanks) about checking for spaces in a regular expression and I was just wondering if I can post to this newsgroup through a regular newsreader? Michael emailed me his response but my post never showed up in the regular postings. I tried being a regular list member but I was getting absolutely flooded (and I mean flooded) with emails from the list so I felt a need to unsubscribe. Using a regular newsreader would help a lot. Thanks. -- Carlos www.internetsuccess.ca -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]