RE: PERL IS NOT A HIGH LEVEL LANGUAGE
HAHAHAHAHA !! -Original Message- From: Humberto Varela [mailto:[EMAIL PROTECTED]] Sent: Friday, August 17, 2001 1:19 PM To: [EMAIL PROTECTED] Subject: Re: PERL IS NOT A HIGH LEVEL LANGUAGE - the understanding of more advanced data structures...with 2 years of serious cobol for example should bring familiarity with files, records, and other such data types. Someone still programs in Cobol? I thought all those Cobol programmers died on New Years Day 2000? -- 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: [ADMIN] Re: [ADMIN] Re: FW: F*** YOU
Agreed. It would be nice not to have to deal with jerks on this list. -Original Message- From: Michael Kelly [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 14, 2001 12:47 PM To: [EMAIL PROTECTED] Subject: Re: [ADMIN] Re: [ADMIN] Re: FW: F*** YOU On 8/14/01 9:48 AM, [EMAIL PROTECTED] wrote: On Tue, Aug 14, 2001 at 11:03:02AM -0500, John ([EMAIL PROTECTED]) spew-ed forth: then do something about this BOZO. I have already emailed 1st.net. what more can I do? John John, You can start by reading what I posted which firstly said no more of this should go to the list, and secondly gave other avenues to take your grievences. Noone on the list wants to be involved in this. Take it off-list. Think before you post, please. Cheers, Kevin Ok, sorry to bring more of this up, but... Can't someone just block this John character from the list? I know I'm already adding a little filter to delete all messages from him, but couldn't the list do that automatically? :) -Michael Kelly Email: [EMAIL PROTECTED] -- 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: number of elements in array is -1?
if $#scans==-1, then the array is empty (of course!) Are you checking to make sure LOGFILE opened correctly? -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Friday, August 10, 2001 9:19 AM To: Perl-Beginners Subject: number of elements in array is -1? Hello everyone, I have a problem. I just want to print the number of elements in an array. Here's the code: my @scans; my $last_host = 192.168.1.1; while (LOGFILE) { push (@scans, $_) if m/$last_host/i; } shouldn't that put all of the results into the @scans array? I know there'd just be a bunch of the same value. $array[0] would equal 192.168.1.1 and $array[1] would equal 192.168.1.1 I try to show the number of elements in the array like so: print $#scans; But that prints -1. I know for a fact there are at least 2 entries in LOGFILE that have an IP of 192.168.1.1. Thanks, Tyler Longren Captain Jack Communications [EMAIL PROTECTED] www.captainjack.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]
RE: number of elements in array is -1?
I thought so. You read through the entire file, so by the time you get to your second while loop, you're at the very end of the file. You need to rewind. -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Friday, August 10, 2001 9:29 AM To: Brett W. McCoy Cc: [EMAIL PROTECTED] Subject: Re: number of elements in array is -1? I did: print $scans[0]; and nothing is printed...where 192.168.1.1 SHOULD be printed... here's what I have: open (LOGFILE, $log_file) || die (Could not open $log_file: $!); my @array; while (LOGFILE) { chomp; push (@array, $_) if m/ida/i; } my $last_host = 192.168.1.1; my @scans; while (LOGFILE) { push (@scans, $_) if m/$last_host/i; } close(LOGFILE); print $scans[0]; On Fri, 10 Aug 2001 10:28:23 -0400 (EDT) Brett W. McCoy [EMAIL PROTECTED] wrote: On Fri, 10 Aug 2001, Tyler Longren wrote: I try to show the number of elements in the array like so: print $#scans; That actually gives the index of the last element, not the actual count of elements. You want: print scalar(@scans); But that prints -1. I know for a fact there are at least 2 entries in LOGFILE that have an IP of 192.168.1.1. Did you dump the array to see if they are actually in there? -- Brett http://www.chapelperilous.net/btfwk/ Your conscience never stops you from doing anything. It just stops you from enjoying it. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: escape sequence for @
If you need to use double quotes, you can say: print somebody\@somewhere.com but if you're not using any other escape sequences or variables, then just use single quotes: print '[EMAIL PROTECTED]' Single quotes force perl to take the string as it is instead of trying to insert the array '@somewhere' into the string. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Thursday, August 09, 2001 3:10 PM To: [EMAIL PROTECTED] Subject: escape sequence for @ How do I print an e-mail address to a file. For example, [EMAIL PROTECTED] -- 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: Hit counters
this explains a lot. only in Windows ... ;) -Original Message- From: Matthew Peter Lyon [mailto:[EMAIL PROTECTED]] Sent: Wednesday, August 08, 2001 4:34 PM To: Sharon Carter; [EMAIL PROTECTED] Subject: Re: Hit counters this is a virus. don't open it. - Original Message - From: Sharon Carter [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, August 08, 2001 1:58 PM Subject: Hit counters Hi! How are you? I send you this file in order to have your advice See you later. Thanks -- 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: pls ignore last msg
Too late -- i already posted. Oh, well! ;) -Original Message- From: Barry Carroll [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 07, 2001 11:12 AM To: '[EMAIL PROTECTED]' Subject: pls ignore last msg sorry guys i got it, silly mistake -- 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: list archives
Yes, i know--that's where i went in the first place, but 'dateindex' only has posts from May 29-June 1, and those are repeated over and over again. Something gives me the impression that this MHonArc thing that they're using isn't working properly ... -Original Message- From: Elaine -HFB- Ashton [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 07, 2001 3:08 PM To: Mooney Christophe-CMOONEY1 Cc: [EMAIL PROTECTED] Subject: Re: list archives Mooney Christophe-CMOONEY1 [[EMAIL PROTECTED]] quoth: *Got a question related to this list: * *I went to the specified archive because i wanted to find an older post, but *it looks like the list only contains this month's postings. Does anyone *know where the older posts are? Are they lost and gone forever? http://lists.perl.org/showlist.cgi?name=beginners http://archive.develooper.com/beginners%40perl.org/dateindex.html e. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Frustrated installing modules!?!
What's PPM? Is this similar to CPAN? -Original Message- From: Wagner-David [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 07, 2001 3:55 PM To: [EMAIL PROTECTED] Subject: RE: Frustrated installing modules!?! Here is my setup for AS using ppm: PPM interactive shell (2.1.2) - type 'help' for available commands. PPM set Commands will be confirmed. Temporary files will be deleted. Case-insensitive searches will be performed. Package installations will continue if a dependency cannot be installed. Tracing info will be written to 'PPM.LOG'. Screens will pause after 24 lines. Query/search results will be verbose. Current PPD repository paths: ActiveState Package Repository: http://ppm.ActiveState.com/cgibin/PPM/ppmserver.pl?urn:/PPMServer Packages will be built under: C:\DOCUME~1\dwagne01\LOCALS~1\Temp PPM Also the three variables needed if behind firewall: HTTP_proxy=http://internet:80 HTTP_proxy_pass=password HTTP_proxy_user=userid Using this under AS 5.6.0 build 623, I am able to download modules to run. Note: Must make sure your password is up to date and either export if not or restart to make certain you are current. Wags ;) -Original Message- From: John Way [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 07, 2001 13:48 To: [EMAIL PROTECTED] Subject: Frustrated installing modules!?! I am truly frustrated that I can't even find any documentation on how to install a module from, say, CPAN! I have activestate's installation of Perl 5.6.1.628 for Windows2000. I downloaded the binary version and have been learning perl for about 4 months or so. The FAQ's say to use ppm to instal modules, but after following the instructions for setting up environment proxy setting variables for WINDOWS NT (not specific for Windows 2000 Professional), the ppm still couldn't connect to the website. Next I tried the old fashioned make method, but when I type c:\perlnmake I get the message 'nmake' is not recognized as an internal or external command,operable program or batch file. I searched the entire hard drive, but there is no nmake or nmake.* Neither of these methods worked for me and I can't locate any troubleshooting documentation! Can anyone help? John Way Confidentiality Notice: *** Privileged/Confidential information may be contained in this message and is intended only for the use of the addressee. Please advise immediately if you or your employer do not consent to Internet e-mail for messages of this kind. If you are not the addressee, or person responsible for delivering to the person addressed, you may not copy or deliver this to anyone else. If you receive this message by mistake, please notify the sender immediately by return e-mail. Thank you. -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Create an array of arrrays from a scalar
hehe -- i tried to do the exact same thing last year. The solution? Mail::*Client from CPAN (your example looks like IMAP, but i'm not sure ...) You may not be crazy now, but if you continue down this dark path, you'll certainly end up there. Trust me. ;) -Original Message- From: Chris Rogers [mailto:[EMAIL PROTECTED]] Sent: Tuesday, August 07, 2001 3:58 PM To: Beginners@Perl. Org (E-mail) Subject: Create an array of arrrays from a scalar Maybe I'm crazy, but I would like to create an array of arrays from a single string. Here's an example of a string: ((TEXT PLAIN (format flowed) NIL NIL 7BIT 206 4 NIL NIL NIL)(TEXT PLAIN (name Display.txt format flowed) NIL NIL 8BIT 16330 412 NIL (attachment (filename Display.txt)) NIL) mixed (boundary =_NextPart_000_36cf_58cd_f54) NIL NIL) This string will be contained a single scalar variable. I have tried a few different things, all of which have failed miserably. My guess is that spaces will need to be changed to commas. Any help would be greatly appreciated. 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: == vs eq What's the difference?
== converts the arguments to numbers. So, even though (1 blah blah blah eq 1) is FALSE, (1 blah blah blah == 1) is TRUE. Similarly, (nichts eq 0) is FALSE, but (nichts == 0) is TRUE. -Original Message- From: CDitty [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 12:22 PM To: [EMAIL PROTECTED] Subject: == vs eq What's the difference? The subject pretty much says it all. Why do some if statements only want to work with eq and others will work with ==? Thanks CDitty -- 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: get rid of the same elements in an array/hash
You will never have duplicate keys in a hash. If you try to use the same key more than once, it will simply overwrite the previous definition: %blah=('a_key' = 'first definition', 'a_key' = 'second definition', 'a_key' = 'YES!!') the key 'a_key' appeared three times, but each time it overwrites the previous definition, so in the end, %blah contains exactly one key and its associated value: $blah{'a_key'} eq 'YES!!' But my guess is that you are trying to weed out duplicates in an array, not a hash, in which case you need to do something like this: @array=qw/one two three two one two three two four five four/; # creates a hash using the elements from @array as keys, which eliminates any duplicates %hash = map {($_,'whatever')} @array; # return the keys back to the array @array=keys %hash; print $_\n for @array; __END__ Which outputs: one two three four five Although probably not in that order. I just wanted to clarify that to make sure you're not trying something like '%hash=@array'. hth! -Original Message- From: Jennifer Pan [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 12:47 PM To: [EMAIL PROTECTED] Subject: get rid of the same elements in an array/hash sorry to ask this as I saw the same question but cannot remember the answer. if I have a hash, how do I get rid of the elements that appear more than once? thank you very much -- 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: Remove White Space
$var=~s/^\s*//; -Original Message- From: Scott Martin [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 3:13 PM To: Perl Help Subject: Remove White Space How can I remove white space from the beginning of a variable? -Scott -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Remove White Space
$var=~/\s*//g; # ;) -Original Message- From: Scott Martin [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 3:56 PM To: Perl Help Subject: RE: Remove White Space After I sent it out, I actually came up with the idea myself after some digging. (go figure) any case, I am now having another problem which, even after some research still proves difficult. I have a variable like: file .htm but what I want to do is trim the white space between file and .htm any ideas? -Scott -Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 4:45 PM To: '[EMAIL PROTECTED]' Subject: RE: Remove White Space -Original Message- From: Scott Martin [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 4:13 PM To: Perl Help Subject: Remove White Space How can I remove white space from the beginning of a variable? This is a FAQ: perldoc -q strip -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Remove White Space
What happens when you try? -Original Message- From: Scott Martin [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 4:05 PM To: 'Mooney Christophe-CMOONEY1' Cc: 'Perl Help' Subject: RE: Remove White Space That's what I thought it would be but still no luck. -Scott -Original Message- From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 4:52 PM To: Perl Help Subject: RE: Remove White Space $var=~/\s*//g; # ;) -Original Message- From: Scott Martin [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 3:56 PM To: Perl Help Subject: RE: Remove White Space After I sent it out, I actually came up with the idea myself after some digging. (go figure) any case, I am now having another problem which, even after some research still proves difficult. I have a variable like: file .htm but what I want to do is trim the white space between file and .htm any ideas? -Scott -Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 4:45 PM To: '[EMAIL PROTECTED]' Subject: RE: Remove White Space -Original Message- From: Scott Martin [mailto:[EMAIL PROTECTED]] Sent: Monday, August 06, 2001 4:13 PM To: Perl Help Subject: Remove White Space How can I remove white space from the beginning of a variable? This is a FAQ: perldoc -q strip -- 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] -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Security Question
Actually, open is only a security hole if you allow the user to tell you what to open at the command line. i don't have the exact message in front of me, but my guess is that someone said something like: $_=STDIN; open(IN,$_|); In which case if the user entered 'rm -rf /', it would try to delete everything. This would be especially disastrous if the script were run as a superuser, in which case everything on the system would irretrievably vanish in the blink of an eye. So don't be afraid to use 'open' if you know exactly what you're opening ... ;) -Original Message- From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 9:41 AM To: Perl Beginners Subject: RE: Security Question 'rm -rf .' is a unix command that removes everything in the current direcotry PERMANENTLY and UNCONDITIONALLY -Original Message- From: Customer Service [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 9:44 AM To: Perl Beginners Subject: Security Question Dear Sirs, I first of all wanted to apologize about sending so many redundant questions to the list. I wasn't aware that my wife was downloading my mail also and I didn't see all of your replies to previous questions. Won't happen again ;-)) I was reading a reply to a question this morning that stated that the open() call is a big security hole because someone could put in ;rm -rf . as the value for $email. What does ;rm -rf . do? Why is it so dangerous? Nathan Garlington [EMAIL PROTECTED] mailto:[EMAIL PROTECTED] -- 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: Splitting a string into a Array of Arrays
You're actually very close. I would just change a couple of things. First of all, you don't need @data as well as @rows. $element is aliased to each element in the array as it loops, so you can re-assign right back into the same array when you split. This will cause the loop to independent of the order in which it reads the elements from @rows, which means you don't need '$i' as well. Second, when you create your nested array, you need to use []. sub quotes { my $content = get_content(); my @rows=split/\n/,$content; foreach my $element (@rows) { $element=[split(/,/,$element)]; } return @rows; } As a matter of personal style, i prefer to take advantage of the default variable, since i find it easier to read, though others may not: sub quotes { my @rows = split /\n/, get_content; $_=[split /,/] for @rows; return @rows; } Or if you want to be COOL like Bob ;) sub quotes {map {[split /,/]} split /\n/, get_content} And i think in this case using 'map' would be okay, since it's going to have to loop over the entire array anyway. Am i wrong ... ? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: perl and graphics
I believe you're looking for Image::Magick from CPAN (www.cpan.org) -Original Message- From: Matt Behrens [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 11:19 AM To: [EMAIL PROTECTED] Subject: perl and graphics Hi all- I'm currently trying to find a way to batch the conversion of thousands of tiff files to jpg files. I have written perl before, but I haven't been able to find much on graphics with PERL. Is this possible? Is it worth the time to try it? Any helpful hints? Thanks for any comments!! Matt -- 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: check array element (HELP)
'%found_one' starts off empty. Everytime we find a new element, we add one to '$found_one{$_}' via '++'. Since '++' is postfix, it occurs AFTER the value is returned. In otherwords, '$found_one{$_}++' returns the current value and then adds one. Now, if the current element has never been read before, then '$found_one{$_}' doesn't exist, and so returns false. '$found_one{$_}++' in this case is equivalent to '$found_one{$_}=1'. In otherwords, we create an entry in '%found_one' with key of '$_'. If, on the other hand, the element was read before, then '$found_one{$_}' returns true. It then increments the value and sets it equal to 2, but we don't care about that, since we've already jumped out of the sub via return. By the end of the loop, if we haven't returned out, we know that each element in '@_' is unique, and '%found_one' has exactly one key for each $_ in @_, each set to 1. So, we just return false. Besides the fact that you introduce a lot of unnecessary variables, the only difference between your sub and mine is that yours performs '$n log $n' comparisons (is that right ... ?) whereas mine only performs '$n'. I don't know enough about perl to know which method is more efficient. It could be that the overhead involved in hashing outweighs the comparisons and array lookups that you used. I don't know. I use this method because it's less cluttered and makes more sense to me. Although, if i were going to write this sub for script i were using, i would DEFINITELY use array-refs like you did. Oh yeah, and another thing; i think for (my $i=0; $i$n; $i++) is preferable to for my $i (0...$n-1) since the latter creates the entire array and then goes through the elements, instead of merely going from one integer to the next. hth! christopher -Original Message- From: Wagner Jeff Civ Logicon/TTMS [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 11:40 AM To: [EMAIL PROTECTED] Subject: RE: check array element (HELP) Hi, I am one of the beginners list's many voyeurs. Can you explain your code? Where does the %found_one hash get its initial value? I understand that @_ represents the list that was passed to the subroutine and that $_ is the current list element for each loop iteration. Does your code assume that the list is sorted? How does it compare to this code fragment? ## sub repeated_elements { my $list = shift;# passed list reference my $n= $#{$list};# subscript of last list element for my $i (0..$n-1) { for my $j ($i+1..$n) { if ($list-[$i] eq $list-[$j]) {return 1} } } return 0; } if (repeated_elements(\@whatever)) { print There are repeated elements\n; } else { print There are no repeated elements\n; } ## Thanks, Jeff -Original Message- From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 08:44 To: [EMAIL PROTECTED] Subject: RE: check array element (HELP) I would probably do this, although i'm sure some smarty-pants could come up with a one-liner ;) sub repeated_elements { my %found_one; for (@_) { return 1 if $found_one{$_}++; } return 0; } if (repeated_elements @whatever) { # there are repeated elements } else { # there are no repeated elements } -Original Message- From: GRANATA ROBERTA [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 31, 2001 9:28 AM To: [EMAIL PROTECTED] Subject: check array element (HELP) --- Erhalten von ZBM.ZAGTA 089/32000-414 31-07-01 15.28 hi All, I have an array of 0...n elements. I want to check that each element of the array, must be different to each other. if it is so - error, else - go on. please, Can somebody help me,to write this code.? thanks in advance, Best Regards, roberta 31-07-01 15.28 Gesendet an - beginners(A)perl.org -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: ref problems
Yes -- i see now that i'm going about this whole thing the wrong way. I'm trying to make the module do too much. It's a bad habit i'm trying to break. I suppose if the luser who uses my package doesn't like what 'bark' does s/he will just have to overload it themselves. ;) Interestingly enough i took a class last year where we each wrote a massive program in C++. I kept asking the professor how to tell what one object should do and what it should leave for another one to do. He never really gave me a straight answer, but he would always get on my case for trying to make my modules god-like. I guess it's just an art--one i have yet to master. ;) -Original Message- From: Jos I. Boumans [mailto:[EMAIL PROTECTED]] Sent: Monday, July 30, 2001 10:14 AM To: Mooney Christophe-CMOONEY1; [EMAIL PROTECTED] Subject: Re: ref problems Hi, I'm not sure you're quite understanding the logic of modules and packages yet... the idea of a module is that you use methods (subroutines belonging to a package) to execute code however, you're making your 'methods' attributes to an object. This quite defeats the purpose and provides nothing in the form of encapsulation. (concider some ev0l subroutine you pass your object to says: sub foo { my $self = shift; $self-{'speak'} = undef; } That would cause serious dying of your script when calling the 'method' Maybe you should raed up on modules a bit first and OO programming in general I wrote a tutorial on http://japh.nu that you might find very interesting, since it deals with jsut these things also, the following perldocs are very usefull perlboot perltoot perltootc hth, Jos Boumans Hello, all -- i have come across an interesting problem. When i run the following script, i get that '$this' in dog::bark is undefined. When i think about it, this makes sense, since call $a_dog-{'speak'}() is like saying dog::bark. Saying $a_dog-{'speak'}($a_dog) on the last line would solve this problem, but it would be nice not to have to worry about passing itself to the function. Does anyone see any alternatives to this? Thanks! #!/local/perl/bin/perl -w use strict; package dog; sub new { my $class=shift; my %this=@_; $this{'speak'}=\bark; bless \%this; } sub bark { my $this=shift; $this || die foo: it's undefined!\n; print $this-{'name'} says woof!\n; } package main; my $a_dog=dog-new(name = 'bart'); $a_dog-{'speak'}(); -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: lost in hashes
Not hard to do when dealing with references! ;) The problem is that you are assigning a REFERENCE TO A HASH to the HASH itself, because you're using '{}' when assigning to %T. $T{d4} has the opposite problem -- it needs to be associated with a SCALAR, ie. a REFERENCE TO A HASH. '()' is a LIST, not a REFERENCE. So, switch your '{}'s and '()'s and it should do what you want it to. Also, when you reference some field from $T{d4}, you need to be sure to deREFERENCE it like this: $T{d4}-{names} So you'll have to change that in the popup_menu. HTH! christopher -Original Message- From: Jerry Preston [mailto:[EMAIL PROTECTED]] Sent: Friday, July 27, 2001 9:12 AM To: begginners Subject: lost in hashes Hi, I just can't see where I have missed it! %T = { d4 = ( names = [ , Ron, Tony, Jeff, Scott, ], ), }; print $query-popup_menu( -name='Test', -values = $T{ d4 }{ names }, -default = '' ); Do you? Thanks for Your help!! Jerry -- 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: lost in hashes
Sure enough, you're right! That's VERY nice to know, since i'm trying to deal with multidemensional lists myself right now. ;) -Original Message- From: Bob Showalter [mailto:[EMAIL PROTECTED]] Sent: Friday, July 27, 2001 9:34 AM To: '[EMAIL PROTECTED]' Subject: RE: lost in hashes -Original Message- From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] Sent: Friday, July 27, 2001 10:21 AM To: begginners Subject: RE: lost in hashes ...Also, when you reference some field from $T{d4}, you need to be sure to deREFERENCE it like this: $T{d4}-{names} So you'll have to change that in the popup_menu. Actually, according to perllol the - is not required when placed between brackets (square or curly). So $T{d4}-{names} and $T{d4}{names} are equivalent. -- 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: in over my head in hashes again
it just takes practice. %T_QUESTION = ( d4 = { names = { 1 = { Q = What is your name, C = [Jerry,Ron,Tony,Jack], A = Jerry } } } ); Notice that every nested hash starts with '{}' -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Recursive find for a file within a directory
use File::Find;) -Original Message- From: Sudarsan.Raghavan [mailto:[EMAIL PROTECTED]] Sent: Friday, July 27, 2001 2:52 PM To: [EMAIL PROTECTED] Subject: Recursive find for a file within a directory Hello, I am new to perl. I want to find for a file recursively within a directory. Is there a perl module already present that will do the job for me, or do I have to write my own. My attempt at the same I am trying this on a VMS machine. #Begin searchDirforFile.pl #Usage perl searchDirforFile.pl filename Directory (optional, defaults to current Directory) use strict; my @dirList; my $fileName; my $srcDir; my $findRet; $fileName= shift; $dirList[0] = shift || '.'; chomp ($fileName); chomp ($dirList[0]); while ($srcDir = shift (@dirList)) { $findRet = findFileinDir ($fileName, $srcDir); if ($findRet == -1) { print Cannot open directory $srcDir for reading\n; } last if ($findRet == 1); } if ($findRet != 1) { print File not found\n; } sub findFileinDir { my $srchFile = $_[0]; my $srchDir = $_[1]; my $fileInDir; opendir DIRHNDL, $srchDir or return -1; while ($fileInDir = readdir DIRHNDL) { $fileInDir =~ s/\.dir\Z//; if (-d $srchDir.$fileInDir) { my $subDir = $srchDir; chop ($subDir); $subDir = $subDir...$fileInDir.]; push (@dirList, $subDir); } elsif ($fileInDir eq $srchFile) { print $srchDir\n; print $fileInDir\n; return 1; } } closedir (DIRHNDL); return 0; } Thanks, Sudarsan -- 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: Read text files only into a hash
Why don't you change your next 'next unless -T $dir/$file'; That will skip over any non-text files, including dirs and '.' -Original Message- From: Shepard, Gregory R [mailto:[EMAIL PROTECTED]] Sent: Friday, July 27, 2001 3:47 PM To: [EMAIL PROTECTED] Subject: Read text files only into a hash All, I am trying to read only text files (using the -T test) from a directory into a hash, and not directories themselves. How do I prevent it from it reading in directories? This sounds like a basic question and know there is probably an easy answer... but I can't think of it. Thanks. @ARGV=$dir; $directory=shift || '.'; opendir DIR, $directory or die Can't open directory $directory: $!\n; my $time_num=1; my $hash_num=0; while ($file = readdir DIR) { next if $file=~/^\./; $dir_file = $dir/$file if -T $dir/$file; @filespecs = stat($dir_file); $filespecs = $filespecs[9].$time_num; $time_table{$filespecs} = $file; $time_num++; } close DIR; -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Read text files only into a hash
Sorry -- let me try that again ... Why don't you change your next statement to: next unless -T $dir/$file || /^\./; -Original Message- From: Shepard, Gregory R [mailto:[EMAIL PROTECTED]] Sent: Friday, July 27, 2001 3:47 PM To: [EMAIL PROTECTED] Subject: Read text files only into a hash All, I am trying to read only text files (using the -T test) from a directory into a hash, and not directories themselves. How do I prevent it from it reading in directories? This sounds like a basic question and know there is probably an easy answer... but I can't think of it. Thanks. @ARGV=$dir; $directory=shift || '.'; opendir DIR, $directory or die Can't open directory $directory: $!\n; my $time_num=1; my $hash_num=0; while ($file = readdir DIR) { next if $file=~/^\./; $dir_file = $dir/$file if -T $dir/$file; @filespecs = stat($dir_file); $filespecs = $filespecs[9].$time_num; $time_table{$filespecs} = $file; $time_num++; } close DIR; -- 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] -- 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: code doesn't work
i think you want to use 'unless' instead of 'until'. also, take advantage of $_'s magic in your print statement: print TEMP unless /ancre/; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
__TAGS__
Where can i find out more information about the __TAGS__ ? BTW what are they really called? Are they directives? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: __TAGS__
Actually, i checked in perlsyn. It uses a couple of them in examples at the very end, but doesn't really talk about them. I frequently use the __END__ tag while i'm debugging so that i can easily comment out a chunk of code at the end. I'm also using the __DATA__ tag, and i was worried that the __END__ tag might stop perl from reading the file at all, in which case i wouldn't get to the __DATA__. I tried it, though, and it seems to work. I don't suppose there's a __BEGIN__ tag, which would allow one to do this: #!/usr/bin/perl __DATA__ blah blah blah __BEGIN__ print while DATA; ... ? -Original Message- From: Jeff 'japhy/Marillion' Pinyan [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 11:22 AM To: Mooney Christophe-CMOONEY1 Cc: [EMAIL PROTECTED] Subject: Re: __TAGS__ On Jul 26, Mooney Christophe-CMOONEY1 said: Where can i find out more information about the __TAGS__ ? BTW what are they really called? Are they directives? These are documented in perlsyn: __END__ end of program __DATA__ end of program, but allow this to be accessed via *PKG::DATA __FILE__ the name of the current file __LINE__ the number of the current line There are also __WARN__ and __DIE__, but they're just special keys in the %SIG hash. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun. Are you a Monk? http://www.perlmonks.com/ http://forums.perlguru.com/ Perl Programmer at RiskMetrics Group, Inc. http://www.riskmetrics.com/ Acacia Fraternity, Rensselaer Chapter. Brother #734 ** Manning Publications, Co, is publishing my Perl Regex book ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: if in a list
That depends on what you're using @mylist for. If you're simply using it to check to see if an element is in the list, then use a hash instead. If you're creating the list element - b push @mylist, $whatever; you can say $myhash{$whatever}=1; Then your search-loop collapses into if ($myhash{'AF1'}) {...} If, for some reason, you need the information in a list and not a hash, then use a grep instead of the for loop: if (grep /^AF1$/, @mylist) {...} HTH! ;) -Original Message- From: Jennifer Pan [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 1:55 PM To: [EMAIL PROTECTED] Subject: if in a list I want to test if AF1 is in my list @mylist; I did: foreach $LIST (@mylist) { if ($LIST = AF1) $boolean = 1; else $boolean = 0; } is there a more elegant way to do it? many thanks jennifer -- 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: if in a list
sorry -- that should read if you're creating the list element-by-element like this: push @mylist, $whatever; you can replace it with this: $myhash{$whatever}=1; -Original Message- From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 2:09 PM To: [EMAIL PROTECTED] Subject: RE: if in a list That depends on what you're using @mylist for. If you're simply using it to check to see if an element is in the list, then use a hash instead. If you're creating the list element - b push @mylist, $whatever; you can say $myhash{$whatever}=1; Then your search-loop collapses into if ($myhash{'AF1'}) {...} If, for some reason, you need the information in a list and not a hash, then use a grep instead of the for loop: if (grep /^AF1$/, @mylist) {...} HTH! ;) -Original Message- From: Jennifer Pan [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 1:55 PM To: [EMAIL PROTECTED] Subject: if in a list I want to test if AF1 is in my list @mylist; I did: foreach $LIST (@mylist) { if ($LIST = AF1) $boolean = 1; else $boolean = 0; } is there a more elegant way to do it? many thanks jennifer -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: __TAGS__
perlDATA!! thank you! -Original Message- From: Paul Johnson [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 2:11 PM To: [EMAIL PROTECTED] Cc: Mooney Christophe-CMOONEY1; [EMAIL PROTECTED] Subject: Re: __TAGS__ On Thu, Jul 26, 2001 at 12:21:38PM -0400, Jeff 'japhy/Marillion' Pinyan wrote: On Jul 26, Mooney Christophe-CMOONEY1 said: Where can i find out more information about the __TAGS__ ? BTW what are they really called? Are they directives? They seem to be called special literals. These are documented in perlsyn: That's perldata __END__ end of program __DATA__ end of program, but allow this to be accessed via *PKG::DATA __FILE__ the name of the current file __LINE__ the number of the current line __PACKAGE__ the name of the current package -- Paul Johnson - [EMAIL PROTECTED] http://www.pjcj.net -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: last until eof unless question
I don't think 'last until eof' will do what you think it's going to do. If 'eof' is true, then the loop exits, and if it's false then it exits anyway because of the 'last' statement. If you're trying to read from STDIN until you get a proper response from the user, then do something like this: while ($email=STDIN) { chomp; last unless $email; warn You entered a blank line: try again!\n; } This loop will skip over any blank lines the user enters. HTH! ;) -Original Message- From: Abdulaziz Ghuloum [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 26, 2001 1:40 PM To: [EMAIL PROTECTED] Subject: Re: last until eof unless question Hello, What does last until eof unless email mean? I don't get what you're after. Can you explain what you're trying to do or include a snippet from your program. Aziz,,, In article 5.0.0.25.0.20010726113250.00a199b0@linus, David Freeman [EMAIL PROTECTED] wrote: in my script i have the line currently reading last unless $email; i changed it to read last until eof unless $email; i get a error message for eof unless for a syntax error. Is there a proper way to phrase this type of arguement so it would work? -- 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]
pushing into a hash
Does anyone know of a slick way to put an array into a hash? For example, given %a= ( -a = 1, -b = 2, -c = 3 ); @b=qw/-x 24 -y 25 -z 26/; Is there a nice way to merge the hash implied by @b into %a to get %a= ( -a = 1, -b = 2, -c = 3, -x = 24, -y = 25, -z = 26 ); without doing something like for $i (0,2,4) { $a{$b[$i]}=$b[$i+1] } For the record, push %a, @b; doesn't work ;) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Changing to new directory.
$pathname =~ s!/[^/]*$!!; -Original Message- From: Yvonne Murphy [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 25, 2001 8:04 AM To: [EMAIL PROTECTED] Subject: Changing to new directory. Hi all, Thanks for all your help with previous questions I've had. What I need to figure out now is how I can strip the actual directory from the following pathname that I have stored in a variable : (Just one sample of what I have but there will be different variations of the $pathname below) $pathname = /home/username/folders/test/bar.h So what I really need to be able to do is remove the filename from the end of the path and once I have the new path I want to be able to change to that directory. So I want to change to say '/home/username/folders/test' I don't have any idea how to do this so any help would be grateful. Thanx, YM -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: chompping periods
If you're sure that there's always a period at the end of the string, use 'chop $str'. If you want to be safe, use '$str=~s/\.$//'. -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 25, 2001 1:29 PM To: Perl Beginners Subject: chompping periods Is there a way to chomp a period? Example: this is a test. to this is a test I just need to remove the period from the end of a string. Thanks, Tyler Longren Captain Jack Communications [EMAIL PROTECTED] www.captainjack.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]
RE: Getting values from a file
That's certainly the way i would do it, but if you really want them stored in scalars instead of hashes, then you can use eval. In other words, instead of: $conf{$key} = $val you can say: eval \$$key = q/$val/ Of course if your lines all start with '-', as you posted, then you'll have to strip that character. -Original Message- From: Jos I. Boumans [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 25, 2001 2:34 PM To: Bob Bondi; Beginners-perl Subject: Re: Getting values from a file assuming you are alright with storing them in a hash as key value pairs, something like this will probably work for you: open I, $ARGV[0] or die $!; my %conf; while(I){ chomp; next unless $_; my ($key,$val) = split /\s*=\s*/; $conf{$key} = $val; } for (keys %conf) { print $_ = $conf{$_}\n } or this, whatever you prefer: open I, $ARGV[0] or die $!; my %conf; { local $/; %conf = map{ chomp; $_ ? split /\s*=\s*/ : undef }split/\n/,I } for (keys %conf) { print $_ = $conf{$_}\n } ### both untested for speed, but if it's a small file it really shouldnt matter hope this helps Jos Boumans I'm planning on starting my perl script with a commandline argument, a filename. I open the file and parse through it line by line, OK, but I'm getting a blank on how to grab the value out of the file for a variable in the script. The file will read like: -TestClass = 3 -TestCase = all -Proxy_IP = 255.255.255.255 -Proxy_Port = 8080 -Url = 101.101.101.10:80/test.html I'll have variable for each item above and I just want to fill-in the values. Is there a way to pull out those values and assign them properly? -- 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: Creating Variable Number of Arrays
perldoc perllol # ;) -Original Message- From: saliminl [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 25, 2001 3:36 PM To: [EMAIL PROTECTED] Subject: Creating Variable Number of Arrays How could I create a variable number of arrays? For example, I need 20 arrays named @array1, @array2, etc. Would concatenating a string work? Neema Salimi [EMAIL PROTECTED] -- 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: basename ?
Why not just use a regex? ($basename)=$file_string=~m!([^/]+)$!; -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 24, 2001 1:44 PM To: [EMAIL PROTECTED] Subject: Re: basename ? Gary, In article [EMAIL PROTECTED], Gary Stainburn wrote: The bit I want to get is: qi_test.exe What I'm getting is: var/spool/exim/qtine/15P4aa-U5-00.exp/qi_test.exe A very simple thing to do here would be to split 'var/spool/exim/qtine/15P4aa-U5-00.exp/qi_test.exe' on '/' chars, and grab the final element of the resulting array: #!/usr/bin/perl -w $file_string = 'var/spool/exim/qtine/15P4aa-U5-00.exp/qi_test.exe'; @path_parts = split(/\//, $file_string); $basename = $path_parts[$#path_parts]; print Basename is: $basename\n; You could also get this by futzing around with File::Basename, if you were of a mind to drag a couple hundred extra lines of code. :) Hope that helps, John -- John Fox [EMAIL PROTECTED] System Administrator, InfoStructure, Ashland OR USA - What is loved endures. And Babylon 5 ... Babylon 5 endures. --Delenn, Rising Stars, Babylon 5 -- 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: foreach question
It's talking about stuff like this: $_='a,b,c,d,e,f,g,h,i,j,k,l'; foreach $word (split /,/) { print $word; } foreach $word (grep /blah/, @somearray) { print $word; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: regexp issues
The expression you're using will match letters at the beginning of a string, but will allow for other stuff at the end. To avoid this, put a $ at the end of your regex. Also, [a-zA-Z] can be replaced with \w, which does the same thing. So, you have $name =~ /^\w+$/ -Original Message- From: Stephanie Stiavetti [mailto:[EMAIL PROTECTED]] Sent: Monday, July 23, 2001 3:47 PM To: '[EMAIL PROTECTED]' Subject: regexp issues I need to make sure that a field contains ONLY letters... and this is the regular expression I'm using: $name=~/^[a-zA-Z]+/ it doesn't seem to be working in the test script that I wrote: #!/usr/bin/perl -w print what's your name?; $name=STDIN; chomp $name; $flag=$name=~/^[a-zA-Z]+/; if (!$flag) { print sorry... try again.\n; } else { print woo hoo!\n; } what am I doing wrong? also, will said regular expression accept foreign characters as letters, like an umlaut? (ö) `°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º Stephanie J. Stiavetti Production Tools Industrial Light + Magic 415-448-3213 -|- [EMAIL PROTECTED] `°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º And then the day came when the risk to stay tight in a bud became more painful than the risk it took to blossom. --Anais Nin `°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º¤,ô¿ô,¤º°``°º -- 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]
cpan installation
I am running CPAN as non-root, installing modules into a wierd location. Now i need the location of a GNU library i installed, which is installed at the same wierd location. I have makepl_arg set to 'PREFIX=/wierd/dir'. What do i need to 'o conf' to make it search '/wierd/dir' for the required library? Thanks! christopher -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: math
'use integer' will force integer calculations. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: stupid question (Use strict)
Although i don't necessarily consider myself one of the smarter people here, i can give you some advice. ;) I assume your script is a CGI and you're calling it through some sort of browser ... ? Try running it independently of the browser. Most likely it will tell you about a some variables you didn't predeclare. Once you know what those variables are, you can predeclare them in two ways (that i know of). One is to say 'my $var' at the first instance of each '$var'. The other is to put 'use vars qw/$var1 $var2 .../;' at the beginning of your script, where '$var1 $var2 ...' are the variables. HTH! - christopher -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Friday, July 20, 2001 2:50 PM To: [EMAIL PROTECTED]; Subject: RE: stupid question (Use strict) it's a pragma. It forces explicit declaration of variables, among other things. One of the smarter people here can tell you the exact details of it. -Original Message- From: Tom Malone [mailto:[EMAIL PROTECTED]] Sent: Friday, July 20, 2001 1:42 PM To: Perl List Subject: RE: stupid question Can someone tell me what use strict; means? Someone told me to use it, but I don't know what it means and it (in combination with something else I did, I'm sure) is causing a 500 internal server error in my very simple script Thanks Tom -Original Message- From: Randal L. Schwartz [mailto:[EMAIL PROTECTED]] Sent: Friday, July 20, 2001 12:59 AM To: [EMAIL PROTECTED]; Mark Saunders Subject: Re: stupid question Mark == Mark Saunders [EMAIL PROTECTED] writes: Mark print Content-type:text/html\n\n; You're missing a space. Content-type: text/html\n\n -- Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095 [EMAIL PROTECTED] URL:http://www.stonehenge.com/merlyn/ Perl/Unix/security consulting, Technical writing, Comedy, etc. etc. See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Variable scope and definition
'use strict' does not require that variables be preDEFINED, but that they be preDECLARED. The my statement accomplishes this. In fact, it doesn't matter where you DEFINE your variables. You could just as easily say: my ($user,$test);# or, alternatively use vars qw/$user $test/; and then define them later. -Original Message- From: perl newbie [mailto:[EMAIL PROTECTED]] Sent: Friday, July 20, 2001 3:25 PM To: [EMAIL PROTECTED] Subject: Re: Variable scope and definition I am trying to understand the correct way to define variables and their scope. Here are two simple PERL ( test1.pl and test2.pl )scripts. test1.pl work fine, while test2.pl does not. Would appreciate any help in understanding why test2.pl is complaining about Global symbols Thanks PN test1.pl #!/usr/bin/perl -w use strict; my $user = $ENV{USER}; my $test = Perl; print User : $user\n; print Test : $test\n; test2.pl #!/usr/bin/perl -w use strict; $user = $ENV{USER}; $test = Perl; print User : $user\n; print Test : $test\n; The only difference in code is this: In test1.pl, the variables are defined using my, while in test2.pl, the variables are defined without use of the keyword my. Here are the results of my attempts at running the scripts : % perl -c test1.pl test.pl syntax OK % perl -c test2.plperl -c test2.pl Global symbol user requires explicit package name at test2.pl line 5. Global symbol test requires explicit package name at test2.pl line 6. Variable $user is not imported at test2.pl line 8. Global symbol user requires explicit package name at test2.pl line 8. Variable $test is not imported at test2.pl line 9. Global symbol test requires explicit package name at test2.pl line 9. test2.pl had compilation errors. __ Do You Yahoo!? Get personalized email addresses from Yahoo! Mail http://personal.mail.yahoo.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]
RE: Comparing Arrays
That's an excellent question, i said to myself; i'll bet there's a module for that! So, i looked on cpan, and it looks like Array::Compare will do the trick. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Help: Starting a script with command line arguments
Command line arguments are passed to the script in the array '@ARGV', not '@_'. '@_' is used for subroutines. -Original Message- From: Bob Bondi [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 19, 2001 12:51 PM To: [EMAIL PROTECTED] Subject: Help: Starting a script with command line arguments My question is: how can I pass arguments to a script from the command line? The script at the tail of this message is what I thought would print the 2 arguments I passed into the script, yet the output for this snippet is: Here ya go: Here ya go: Count is: 0 Not enough arguments to get started #\perl\bin use strict; # use strict! It will save you many headaches use File::Basename; use Carp; my $count = @_; print Here ya go: $_[0]\n; print Here ya go: $_[1]\n; print Count is: $count\n; carp Not enough arguments to get started unless $count 0; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: effect of while on filehandle
After the while statement on line 9 is finished, the entire file has been read and there is nothing left to read. You either close or reopen, or a better alternative might be to use the 'seek' function -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 17, 2001 8:49 AM To: Perl Discuss Subject: effect of while on filehandle 1:#!/usr/bin/perl -w 2: 3:use strict; 4: 5:my $host; 6: 7:open FH, lunarmedia; 8: 9:while (FH) { 10: $host = $_; 11: if ( $host =~ /^host/ ) { 12:$host =~ s/^hostname\s(.*)/$1/; 13:chomp $host; 14: } 15:} 16:open NFH, $host; 17: print NFH FH; 18:close NFH; 19:close FH; this script is just a test of sorts for a snippet of code to go into a larger script. my issue is that the print statement on line 17 doesnt seem to work. the file referenced by $host in line 16 gets created, however none of FH's contents are placed in NFH. do i need to re-open FH after the while statement in order for this print to work? and if so, why is it automagically being closed? thanks -charles -- 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]
while ... continue loops
I have been programming perl for quite some time, but i have never used a 'continue' block. It seems just as easy to put any code that one would normally put in a continue right into the loop itself. What is the purpose of a continue block? Is there a time where a continue might be prefered to simply having one block for the whole loop? Thanks! christopher -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: if something equals nothing
Exactly like that, except using 'eq' instead of '=='. A slightly easier way, though, would be to say if (!$something) { ... blah blah ... } Since $something will return false in a boolean context (if it is empty) -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 17, 2001 12:56 PM To: Perl Beginners Subject: if something equals nothing How do I do: if ($something == ) { # do something } in perl? Thanks, Tyler -- 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: if something equals nothing
Is this the code you're trying to use? Because if it is, then the problem is that you're checking $options{a} twice, instead of checking $options{a} and $options{i} ... ? -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 17, 2001 1:05 PM To: Mooney Christophe-CMOONEY1; Perl Beginners Subject: Re: if something equals nothing That doesn't seem to work. I want if a variable doesn't equal anything, then do something. Here's a piece: if ($options{a} eq $options{a} eq ) { print Usage: log.pl [-d] -a -i [n]\n -d : specify device. If nothing, eth0 is used -a* : specify alias number -i* : specify ip number to assign to alias -n : specify netmask. If nothing, 255.255.255.0 is used Options with a * are required!\n\n; exit; } - Original Message - From: Mooney Christophe-CMOONEY1 [EMAIL PROTECTED] To: Perl Beginners [EMAIL PROTECTED] Sent: Tuesday, July 17, 2001 12:59 PM Subject: RE: if something equals nothing Exactly like that, except using 'eq' instead of '=='. A slightly easier way, though, would be to say if (!$something) { ... blah blah ... } Since $something will return false in a boolean context (if it is empty) -Original Message- From: Tyler Longren [mailto:[EMAIL PROTECTED]] Sent: Tuesday, July 17, 2001 12:56 PM To: Perl Beginners Subject: if something equals nothing How do I do: if ($something == ) { # do something } in perl? Thanks, Tyler -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: upper-casing the first char hashs of hashs
use ucfirst instead of uc -Original Message- From: David Gilden [mailto:[EMAIL PROTECTED]] Sent: Monday, July 16, 2001 12:28 PM To: [EMAIL PROTECTED] Subject: upper-casing the first char hashs of hashs Hello, The following uppercase'S the whole string, when all I want is the first letter. uppercase($bears-{rec$n}{name}), uc($bears-{rec$n}{type}) # works but caps the whole string } u\$bears-{rec$n}{type} # does not work... sub uppercase{ ($s) = @_; \u$s = scalar $s; ## does not work return $s; } another version: sub uppercase{ ($s) = @_; return uc($s); # works but caps the whole string } lastly, in this hash of hashs.. $bears = { rec1 = { type = 'sweater', name = 'sweaterie', color = 'golden brown', food = 'mixed beries', }, one of many... more recs heres } is $ (scalar) $bears, correct? should not be %bears How would I get the lenght of $bears if I wanted to a: for (0 .. # true lenght of $bears ) and as it is, I can not do the following, that you would use will normal hashs foreach my $key (sort keys %bears ) { Thanks good day, Dave G. --- ** * Cora Connection Your West African Music Source * * http://www.coraconnection.com/ * * Resources, Recordings, Instruments More! * ** -- 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: If value missing?
An empty string will return false in a boolean context. So, unless ($date1) { $date1=$date2; } will work. Personally, i prefer: $date1 ||= $date2; It seems more 'perlish' ;) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Regex......some help quickly!!!!
This will take all of the include files it finds in FILE and store them in the array @headers. while (FILE) { /^#include\s+([^]+)/; push @headers, $1; } Fridays can definitely be killers! ;) -Original Message- From: Yvonne Murphy [mailto:[EMAIL PROTECTED]] Sent: Friday, July 13, 2001 9:46 AM To: [EMAIL PROTECTED] Subject: Regex..some help quickly Hi All, It's Friday evening and my brain is already beginning to close down for the weekend although I haven't yet given it permission to do so! I need to get this regex problem I have sorted soon, but my brain refuses to co-operate with me. I need to match the following type of #include statement found in a C header file: #include test/bar.h #include other/foo.h I need to be able to work on the actual header files so I need to be able to store the directory pathnames in a varible. Any idea/help/suggestions would be so gratefully appreciated Thanks in advance Mich -- 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: Regex......some help quickly!!!!
do::h!! it looks like friday is getting the best of me, too! while (FILE) { if (/^#include\s+([^]+)/) {push @headers, $1} } -Original Message- From: Mooney Christophe-CMOONEY1 [mailto:[EMAIL PROTECTED]] Sent: Friday, July 13, 2001 10:02 AM To: [EMAIL PROTECTED] Subject: RE: Regex..some help quickly This will take all of the include files it finds in FILE and store them in the array @headers. while (FILE) { /^#include\s+([^]+)/; push @headers, $1; } Fridays can definitely be killers! ;) -Original Message- From: Yvonne Murphy [mailto:[EMAIL PROTECTED]] Sent: Friday, July 13, 2001 9:46 AM To: [EMAIL PROTECTED] Subject: Regex..some help quickly Hi All, It's Friday evening and my brain is already beginning to close down for the weekend although I haven't yet given it permission to do so! I need to get this regex problem I have sorted soon, but my brain refuses to co-operate with me. I need to match the following type of #include statement found in a C header file: #include test/bar.h #include other/foo.h I need to be able to work on the actual header files so I need to be able to store the directory pathnames in a varible. Any idea/help/suggestions would be so gratefully appreciated Thanks in advance Mich -- 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] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: How could I call a C-Programm
You can embed your C in perl using XS. perldoc perlxstut is an excellent place to start! -Original Message- From: Akshay Arora [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 12, 2001 8:15 AM To: Jürgen Prietl Cc: [EMAIL PROTECTED] Subject: Re: How could I call a C-Programm system call as the quickest solution, however I'm sure someone in this group knows of a perl module that might do this better? $rv = `cprog @args`; Jürgen Prietl wrote: Hi everybody! I want to call a external C-Programm with a parameter and a returnvalue from my perlprogramm. Could somebody help me ? Thanks a lot Jürgen -- GAMED mbH Harter Straße 48 A-8053 Graz Austria Phone: +43 (0)316 27 86 60-16 Fax: +43 (0)316 27 86 60-10 EMail: [EMAIL PROTECTED]
RE: Problem with associative array
Ah -- of course. you need to chomp your $key when you read from STDIN. -Original Message- From: jatuporn [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 12, 2001 9:54 AM To: [EMAIL PROTECTED] Subject: Problem with associative array I try to write a program that reads a file with two fields.The first field is a costumer ID and the second is the costumer name by using ! as a seperator between 2 fields. Store costumer ID as the key and the costumer name as value into a hash. My code is below, I have a problem that $info{ $key} does not show the value. What is the problem ? How to change it? Thank you. * myfile.pl * $filename =costumer.txt; open(FILE,$filename ) or die (can not open file : $filename); while ($line = FILE) { $line =~ s/\s+/ /g; ($id,$name) = split(/!/,$line,2); $info{$id} = $name; } print Enter id:; $key = STDIN; print (ID: $key NAME : $info{ $key} \n); * costumer.dat ** 001!test1 002!test2 003!test3
RE: open FILE problem
In your die command, say: die cannot open $LINE: $!\n; This will give you a hint as to what's going wrong. -Original Message- From: Maxim Berlin [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 12, 2001 11:51 AM To: [EMAIL PROTECTED] Subject: Re: open FILE problem Hello Jennifer, Thursday, July 12, 2001, Jennifer Pan [EMAIL PROTECTED] wrote: JP Hello all, I came across this problem opening up files that are fed in JP from command line using ls. I do not know why this script did not JP work. Appreciated any input. [...] JP at prompt I typed JP ls *.txt | perl format.pl JP it never worked what OS do you use? script works well on my freebsd. JP it always die cannot open $LINE. please show me output, exactly how your script produced. JP I don't understand why me too :) Best wishes, Maximmailto:[EMAIL PROTECTED]
RE: multiple entry/exit points
Personally, i am very liberal with my lasts/breaks/returns/gotos. There is definitely something to be said for strictness. From a theoretical point of view, the code flows better. For example, it is easier to diagram and easier to debug. If i write code for the company i work for, i follow their rules, which usually means only one return statement in a sub/function and no lasts/breaks in my loops. The word 'goto' is considered profane. From a practical point of view, this sort of strict adherence to an abstract philosopy can take away from the efficiency of the program and make it more cumbersome to write. David's words are wise: q/Use your judgement based on the problem... don't stick to one philosophy or the other just because./ Well said.
FW: searching for a string of characters after another string of characters
If i understand you correctly, you're trying to extract exactly one line out of a file. I would do this: while (IN) { if (/^hostname\s+(\S+)$/) # or some other regex derivative { $hostname=$1; last; } } -Original Message- From: Grossner, Tim X. (AIT) [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 12, 2001 3:03 PM To: [EMAIL PROTECTED] Subject: searching for a string of characters after another string of characters How would I do this: file A contains a line of characters always looking like hostname X. I want to take the X and assign that to a scalar...I tried making an array out of it by using grep to search for the line starting with hostname, but then the one and only element of the array is hostname X and I cant figure out how to extract the X out... Any help would be greatly appreciated. __ Tim Grossner Field Operations ManagerCCNA, MCP, A+ Southwestern Bell Datacom voice - 217-522-7564 pager - 217-467-3148 cell - 217-971-3060 data - [EMAIL PROTECTED]
RE: concatenate $FILENAME and .yyy
make like pacman and CHOMP IT !!! ;) $FILENAME = STDIN; chomp $FILENAME; ... -Original Message- From: Jennifer Pan [mailto:[EMAIL PROTECTED]] Sent: Thursday, July 12, 2001 3:49 PM To: [EMAIL PROTECTED] Subject: concatenate $FILENAME and .yyy Hello all, I stdin a file name: xxx.txt and I would like to have a output file name called x.txt.yyy This is how I do it $FILENAME = STDIN; $output = $FILENAME.y; print $output; And the result is only .yyy How do I concatenate $FILENAME and .yyy? Thank you
RE: Simple question about whiles and files...
actually, from what i understand, while (ARGV) and while () are special syntaxes. as soon as you add the , perl doesn't interpret it in the special way (ie. setting $_ to each line of the file) i usually do this: while () { last if /End of list/; bla bla bla } -Original Message- From: Guilherme Pinto [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 11, 2001 2:12 PM To: 'Sebadamus'; [EMAIL PROTECTED] Subject: RE: Simple question about whiles and files... while (ARGV and $_ =! /End of list/) Try that... -Original Message- From: Sebadamus [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 11, 2001 12:27 PM To: [EMAIL PROTECTED] Subject: Simple question about whiles and files... Does anybody knows why I cant make this to work as I want? :-) while (ARGV and $_!=~/End of list/) { bla bla bla } So, with this I want to process the file in ARGV until EOF, and each line must be distinct than /End of list/. So, if it is EOF or the current line is that string... the WHILE should exit... Can anybody HELPPP me...? Thanks you very much, Sebastian.