Re: sequential value check
> > > > Uri> post the output line from that command. do not let your emailer mung it > or word wrap it. show the part you want to extract out. there may be > easier ways to get it with a regex and not with split. I think you may be right. I would like to pull the numerics out from the id= section. Sample output: #begin code output HPING www.microsoft.com (en1 207.46.19.190): S set, 40 headers + 0 data bytes len=46 ip=207.46.19.190 ttl=64 DF id=21409 sport=80 flags=SA seq=0 win=5840 rtt=102.8 ms HPING www.microsoft.com (en1 207.46.19.190): S set, 40 headers + 0 data bytes len=46 ip=207.46.19.190 ttl=64 DF id=21804 sport=80 flags=SA seq=0 win=5840 rtt=1.5 ms HPING www.microsoft.com (en1 207.46.19.190): S set, 40 headers + 0 data bytes len=46 ip=207.46.19.190 ttl=64 DF id=23882 sport=80 flags=SA seq=0 win=5840 rtt=6.4 ms HPING www.microsoft.com (en1 207.46.19.190): S set, 40 headers + 0 data bytes len=46 ip=207.46.19.190 ttl=64 DF id=19047 sport=80 flags=SA seq=0 win=5840 rtt=1.7 ms HPING www.microsoft.com (en1 207.46.19.190): S set, 40 headers + 0 data bytes len=46 ip=207.46.19.190 ttl=64 DF id=30842 sport=80 flags=SA seq=0 win=5840 rtt=1.4 ms # End code output As seen above, what I am looking for is pulling the id= field -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
> > > Uri> no need for the = () as all arrays are created empty. I wasn't sure if strict would bark or not, so I figured better safe than sorry. > > Uri> someone told you that le is wrong for numeric comparison. and WHAT do > you think is in $_ there? you never explicitly set it. it may have some > value from the loop index but that is meaningless. think about your data > when you use it. was it set properly? what should it contain? print it > to make sure. I contains data and numerics id=, that is why I'm using them. I did print it before looking to compare as I normally make habit of and it is printing the value as expected. > > Uri> ge is for string compare. >= is for numeric. See above comment -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
On Feb 9, 2010, at 10:10 AM, Steve Bertrand wrote: > Uri Guttman wrote: > >> CS> foreach (@hping_array){ >> >> foreach my $ping ( @hping_array){ > > Uri showed right above how to avoid using $_. eg instead of: > I didn't read/understand that fully as to the problem at hand. I apologize. > > You will appreciate this in longer programs, as it is very clear as to > what the variable is for, and which scope it belongs to. > > Steve Thanks for the input Steve! -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
>> SB> # ignoring the fact that you were advised to use named variables >> # instead of $_ where possible, here is one way to do it: I do not see how I can get away from using $_ because each iteration through the loop will be a different variable and thus a different array element. This is why I continue to choose to use $_ until someone can show me how it might be easier or cleaner to perform 5 iterations, changing the value every time without using it. >> >>> elsif ($_ ge $hping_compare){ >> >> elsif ( ( $_ + 100 ) >= $hping_compare ) { I think this is more along the lines of what I am trying to do. I am checking to see if the current array element is 100 or more than the base element of $hping_compare. The $hping_compare is the value the want to base the greater than or equal to off of. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
#!/usr/bin/perl use warnings; use strict; my $hping; my $hping_compare; my @hping_array = (); for (1 .. 5){ $hping = `sudo hping3 www.microsoft.com -S -p 80 -c 1`; push @hping_array,(split'\ ',$hping)[15]; } $hping_compare = $hping_array[0]; foreach (@hping_array){ if ($_ le $hping_compare){ print "Appears to be load balancing\n"; } elsif ($_ ge $hping_compare){ print "Appears to be load balancing\n"; } else{ print "Does not appear to be load balancing\n"; } } So now there is my new code. It all runs as expected and the with the suggestions of Uri. The problem still remains that I cannot find any documentation or search results on how one would compare as I have asked from the beginning. I need the ge value to be greater than by 100. If it is not greater than by 100, then it is a different value. With that in mind. Is it possible to do such a comparison? I need to do such an evaluation on the elsif above. in pseudocode it would be: If (the current array element is 100 or more greater than the base array element){ print " Appears to be load balancing\n" } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
> URI> still no warnings and strict. USE THEM. > > do it now. add them and declare all your variables. it will save your > ass. > I am running -w when I run the code. > > URI> what is the \ doing there. it makes the space into a space. it is not > seen by split or the regex engine. This is the ONLY way I can get the ID=x value. I tried both your example and many others. They all produced a single character, not the complete value. This is producing the exact result. So obviously something is using it. > > URI> why the quotes? you don't need to quote something if it is a single value Point taken, I will remove them. > > > URI> use named variables and not $_ whenever you can. it makes for better > code and it is easier to follow. there are cases where $_ must be used > and some places where it is good but names are better in general I'm getting 5 values and I need to do something different with each of them. I believe that is when $_ is helpful as each iteration through the loop will be a different value. It seems to be to be a shorter way and relatively clean to do in this instance. If there is a better way , please enlighten me. > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
Ok. So again, thanks for getting me on the right track. I am now at my compare routine. This is where I cannot figure out how to compare within 100. My first instinct is to write something like the following: #!/usr/bin/perl -w for (1 .. 5){ my $hping = `sudo hping3 www.microsoft.com -S -p 80 -c 1`; push @hping_array,(split'\ ',$hping)[15]; } $hping_compare = "$hping_array[0]"; foreach (@hping_array){ if ($_ le $hping_compare){ print "Appears to be load balancing\n"; } elsif ($_ ge $hping_compare){ print "Does not appear to be load balancing\n"; } else{ print "Something Else\n"; } } I cannot find any reference in any documentation or Google that says I can say ge or le 100 or more. What I am trying to do is say if the 2, 3,4 and 5 values are less than or equal to, then print "We are probably load balancing". Elsif we are greater than by more than 100 print "We are probably load balancing". Else if we are greater than but less than 100 greater than print "we are probably not load balancing. It seems like smart search might be along the right lines, but I can't find any similar examples. On Feb 8, 2010, at 7:19 PM, Uri Guttman wrote: >>>>>> "CS" == Curt Shaffer writes: > > CS> OK. So I have tried some things. I guess the largest issue that I > CS> can't find an answer for elsewhere is how to evaluate variables to > CS> be >, = or <100 in one evaluation. Before I get there, obviously > CS> I need to get the variables. > > CS> @hping_array = (); > > you are not using strict and warnings. always ask perl for all the help > it can give you. > > CS> $hcount = 1; > CS> for (; $hcount < 5;){ > > that is not perlish. > > for ( 1 .. 5 ) { > > no need for a counter since you don't even use it. > > CS> system ("sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'"); > > system doesn't return any output to the program, just to stdout. you > need qx or backticks to do this. and why shell out to awk when perl can > do that for you? > > my $hping = `sudo hping3 $domain -S -p 80 -c 1` ; > > then parse out the field value you want. i don't know hping3's format > but you seem to want the 5th white space separated field. this could be > off by one as iirc awk is 1 based on fields but perl is 0 based. > > push( @hpings, (split ' ', $hping)[5] ; > > > CS> chomp; > > that is chomping $_ is not even set. enabling warnings would have told > you this. > > CS> push hping_array, $_; > > where is the @ in that array name? that won't even compile. please make > sure your code at least compiles before posting it. > > you seem to think system puts its output into $_. where did you get that > idea? > > CS> $hcount++; > > not needed as i said above > > CS> } > CS> print "@hping_array\n"; > > CS> So the code is trying to run the hping3 command against $domain. I > CS> am awking for $5 which is the IPID value in the response. I am > CS> trying to push it into the array @hping_array. This should happen > CS> 5 times. > > well, it doesn't. > > > CS> Then I'm printing @hping_array. I'm only getting one value and it > CS> is actually the whole response from hping. It seems to not respect > CS> the awk. > > no, that isn't true. the system call is sending hping's output to stdout > (via awk but maybe that code is broken too. my awk is massively > rusty). your print is printing nothing (which warnings would also have > told you). > > CS> I have done this partially with just doing my $hping_result = > CS> `sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'; So I know the > CS> system command by itself is working. > > if you know about backticks, why did you switch to system? please read > the docs and learn the difference between the two. > > uri > > -- > Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- > - Perl Code Review , Architecture, Development, Training, Support -- > - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
Thanks for the clue. I have narrowed some things down. The counter is much nicer. I just need to get a better split I think as I'm not getting the grouping I would like. On Feb 8, 2010, at 7:19 PM, Uri Guttman wrote: >>>>>> "CS" == Curt Shaffer writes: > > CS> OK. So I have tried some things. I guess the largest issue that I > CS> can't find an answer for elsewhere is how to evaluate variables to > CS> be >, = or <100 in one evaluation. Before I get there, obviously > CS> I need to get the variables. > > CS> @hping_array = (); > > you are not using strict and warnings. always ask perl for all the help > it can give you. > > CS> $hcount = 1; > CS> for (; $hcount < 5;){ > > that is not perlish. > > for ( 1 .. 5 ) { > > no need for a counter since you don't even use it. > > CS> system ("sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'"); > > system doesn't return any output to the program, just to stdout. you > need qx or backticks to do this. and why shell out to awk when perl can > do that for you? > > my $hping = `sudo hping3 $domain -S -p 80 -c 1` ; > > then parse out the field value you want. i don't know hping3's format > but you seem to want the 5th white space separated field. this could be > off by one as iirc awk is 1 based on fields but perl is 0 based. > > push( @hpings, (split ' ', $hping)[5] ; > > > CS> chomp; > > that is chomping $_ is not even set. enabling warnings would have told > you this. > > CS> push hping_array, $_; > > where is the @ in that array name? that won't even compile. please make > sure your code at least compiles before posting it. > > you seem to think system puts its output into $_. where did you get that > idea? > > CS> $hcount++; > > not needed as i said above > > CS> } > CS> print "@hping_array\n"; > > CS> So the code is trying to run the hping3 command against $domain. I > CS> am awking for $5 which is the IPID value in the response. I am > CS> trying to push it into the array @hping_array. This should happen > CS> 5 times. > > well, it doesn't. > > > CS> Then I'm printing @hping_array. I'm only getting one value and it > CS> is actually the whole response from hping. It seems to not respect > CS> the awk. > > no, that isn't true. the system call is sending hping's output to stdout > (via awk but maybe that code is broken too. my awk is massively > rusty). your print is printing nothing (which warnings would also have > told you). > > CS> I have done this partially with just doing my $hping_result = > CS> `sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'; So I know the > CS> system command by itself is working. > > if you know about backticks, why did you switch to system? please read > the docs and learn the difference between the two. > > uri > > -- > Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- > - Perl Code Review , Architecture, Development, Training, Support -- > - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
Thanks Jim. I see my error now. I didn't realize you could just backtick in a for like that. On Feb 8, 2010, at 7:06 PM, Jim Gibson wrote: > On 2/8/10 Mon Feb 8, 2010 3:55 PM, "Curt Shaffer" > scribbled: > >> OK. So I have tried some things. I guess the largest issue that I can't find >> an answer for elsewhere is how to evaluate variables to be >, = or <100 in >> one >> evaluation. >> >> Before I get there, obviously I need to get the variables. >> >> Here is what I am trying to do for that: >> >> @hping_array = (); >> $hcount = 1; >> for (; $hcount < 5;){ >> >>system ("sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'"); >>chomp; >>push hping_array, $_; >>$hcount++; >> } >> print "@hping_array\n"; >> >> So the code is trying to run the hping3 command against $domain. I am awking >> for $5 which is the IPID value in the response. I am trying to push it into >> the array @hping_array. This should happen 5 times. >> >> Then I'm printing @hping_array. I'm only getting one value and it is actually >> the whole response from hping. It seems to not respect the awk. > > The system function does not return the output of the external command to > the callsign Perl program. > > See perldoc -q "output of a command" > "Why can't I get the output of a command with system()? > > > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: sequential value check
OK. So I have tried some things. I guess the largest issue that I can't find an answer for elsewhere is how to evaluate variables to be >, = or <100 in one evaluation. Before I get there, obviously I need to get the variables. Here is what I am trying to do for that: @hping_array = (); $hcount = 1; for (; $hcount < 5;){ system ("sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'"); chomp; push hping_array, $_; $hcount++; } print "@hping_array\n"; So the code is trying to run the hping3 command against $domain. I am awking for $5 which is the IPID value in the response. I am trying to push it into the array @hping_array. This should happen 5 times. Then I'm printing @hping_array. I'm only getting one value and it is actually the whole response from hping. It seems to not respect the awk. #example output HPING www.example.com (en1 xxx.xxx.xxx.xxx): S set, 40 headers + 0 data bytes len=46 ip=xxx.xxx.xxx.xxx ttl=64 DF id=2041 sport=80 flags=SA seq=0 win=5840 rtt=1.4 ms I have done this partially with just doing my $hping_result = `sudo hping3 $domain -S -p 80 -c 1|awk '{print $5}'; So I know the system command by itself is working. So first question is what can help me get just the $5 into array 5 times. Then I can move on to evaluation of the array values. On Feb 8, 2010, at 6:03 PM, Uri Guttman wrote: >>>>>> "CS" == Curt Shaffer writes: > > CS> I'm trying to figure out a way to compare a couple values to see > CS> if they are sequential or not. I'm running a for loop and > CS> grabbing a value and setting a variable through each iteration. At > CS> the end I would like to examine the results and see if they are > CS> sequential or not. > > CS> If the values are less or more than 100 of the last then print > CS> something like "not sequential". If they are equal or less than > CS> 100 greater then the last then print "possibly sequential". > > this sounds like an easy problem. why don't you try to code it up and > then post that code here. then we can help you with your solution. > > CS> Can anyone point me at a way to do this? > > it is best to work it out for yourself and then ask for help. this is a > simple problem that shouldn't need guidance for a solution. just write > code that reflects what you said in english. if you have trouble, write > more specific english with concrete details. that is easier to translate > to code. > > thanx, > > uri > > -- > Uri Guttman -- u...@stemsystems.com http://www.sysarch.com -- > - Perl Code Review , Architecture, Development, Training, Support -- > - Gourmet Hot Cocoa Mix http://bestfriendscocoa.com - -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
sequential value check
I'm trying to figure out a way to compare a couple values to see if they are sequential or not. I'm running a for loop and grabbing a value and setting a variable through each iteration. At the end I would like to examine the results and see if they are sequential or not. If the values are less or more than 100 of the last then print something like "not sequential". If they are equal or less than 100 greater then the last then print "possibly sequential". Can anyone point me at a way to do this? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
RE: odd variable result
They all seem to skip the awk command. For your open example, I am confused. It gives me the error: failed opening snmpget No such file or directory at ./test.pl line 5. Thanks -Original Message- From: Derek B. Smith [mailto:[EMAIL PROTECTED] Sent: Monday, August 28, 2006 10:05 AM To: Curt Shaffer; Perl List Subject: Re: odd variable result try this syntax: my $test = system ("/usr/bin/snmpget -v1 10.1.11.18 -c secret .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}'"); or my $test = qx(you command above w/no quotes needed); or open (SNMP, "snmpget -v1 10.1.11.18 -c secret .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1" ) or die "failed opening snmpget $!"; foreach () { my $test = (split)[4]; } close SNMP or warn $!; --- Curt Shaffer <[EMAIL PROTECTED]> wrote: > List, > > > > I am trying to set a variable based on a system > call. Here is my code: > > > > #!/usr/bin/perl > > > > use strict; > > > > > > my $test = system `/usr/bin/snmpget -v1 10.1.11.18 > -c secret > .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print > $4}'`; > > print "$test\n"; > > > > When I run that command from the command line it > works as desired. When I > run the script with the system command in " rather > than ` it returns the > whole value rather than the $4 that I need, then the > print $test returns 0. > When I run the script as above the print $test it > appears to set the > variable but produces a -1 which is not in the value > that is returned at > all. Anyone have some guidance for me on how to do > this properly? > > > > Thanks > > > > Curt > > __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
odd variable result
List, I am trying to set a variable based on a system call. Here is my code: #!/usr/bin/perl use strict; my $test = system `/usr/bin/snmpget -v1 10.1.11.18 -c secret .1.3.6.1.4.1.710.7.1.5.1.23.1.13.1|awk '{print $4}'`; print "$test\n"; When I run that command from the command line it works as desired. When I run the script with the system command in " rather than ` it returns the whole value rather than the $4 that I need, then the print $test returns 0. When I run the script as above the print $test it appears to set the variable but produces a -1 which is not in the value that is returned at all. Anyone have some guidance for me on how to do this properly? Thanks Curt
RE: FW: suggestion for sftp process
-Original Message- From: Chas Owens [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 14, 2006 11:48 AM To: Curt Shaffer Cc: beginners@perl.org Subject: Re: FW: suggestion for sftp process On 3/14/06, Curt Shaffer <[EMAIL PROTECTED]> wrote: > I have a small update to this post. I found out that I will be able to get > all of the files in the remote directory. Unfortunately I do not see a way > to do this with Net::SFTP. There is no mget function and * does not seem to > work for the file name. > Thanks > Curt Just loop over the files in the directory. for my $file (map { $_->{filename} } $sftp->ls('/path') { $sftp->get("/path/$file"); } This is what I have now: my @files = $sftp->ls($remotedir); foreach (@files){ $sftp->get("$_"); print "recieving $_...\n"; } print "Complete!\n"; but what I get for each loop in debug is the following: linuxbox: sftp: Sent message T:17 I:30 linuxbox sftp: Received stat reply T:101 I:30 Couldn't stat remote file: No such file or directory at ./sftptest line 24 recieving HASH(0x9dbb0ac)... of course the HASH is different for each loop. Any ideas? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
RE: FW: suggestion for sftp process
-Original Message- From: KyLiE [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 14, 2006 10:36 AM To: Curt Shaffer Subject: Re: FW: suggestion for sftp process Curt Shaffer wrote: >I have a small update to this post. I found out that I will be able to get >all of the files in the remote directory. Unfortunately I do not see a way >to do this with Net::SFTP. There is no mget function and * does not seem to >work for the file name. > > > >Thanks > > > >Curt > > > > _ > >From: Curt Shaffer [mailto:[EMAIL PROTECTED] >Sent: Tuesday, March 14, 2006 9:45 AM >To: beginners@perl.org >Subject: suggestion for sftp process > > > >I am writing a process that will need to establish a SFTP connection with a >remote server, pull a file down and copy it to an archive and system folder. >I also have to do the opposite where I will need to get a file from a system >directory and push it via SFTP to a remote server. Now I have the push part >of this working fine. I just look for a matching regex of the filename and >put it where it needs to go. The issue I have is that the file name will >change every time just a little (i.e. has a date stamp and index) so where >regex works locally, I am lost at how to expect the date stamp and index >from the remote file. > > > >Any help will be appreciated. > > > >Curt > > > > > > > > > > Exactly, unfortunately Net::SFTP dont have support for * or any other comodin, I try it before,what I do and suggest to you is to create an XML with all the entries and exits that you want to do (files, directories, etc) you can create your own module that, with LibXML, create a DOM tree and send orput your files with Net::SFTP It appears that Net::SFTP::Recursive might hold what I am looking for. It has a file_pat option that will match patterns unless I am reading too much into it. I am trying it out now. I will post the outcome. Thanks Curt -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
FW: suggestion for sftp process
I have a small update to this post. I found out that I will be able to get all of the files in the remote directory. Unfortunately I do not see a way to do this with Net::SFTP. There is no mget function and * does not seem to work for the file name. Thanks Curt _ From: Curt Shaffer [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 14, 2006 9:45 AM To: beginners@perl.org Subject: suggestion for sftp process I am writing a process that will need to establish a SFTP connection with a remote server, pull a file down and copy it to an archive and system folder. I also have to do the opposite where I will need to get a file from a system directory and push it via SFTP to a remote server. Now I have the push part of this working fine. I just look for a matching regex of the filename and put it where it needs to go. The issue I have is that the file name will change every time just a little (i.e. has a date stamp and index) so where regex works locally, I am lost at how to expect the date stamp and index from the remote file. Any help will be appreciated. Curt
suggestion for sftp process
I am writing a process that will need to establish a SFTP connection with a remote server, pull a file down and copy it to an archive and system folder. I also have to do the opposite where I will need to get a file from a system directory and push it via SFTP to a remote server. Now I have the push part of this working fine. I just look for a matching regex of the filename and put it where it needs to go. The issue I have is that the file name will change every time just a little (i.e. has a date stamp and index) so where regex works locally, I am lost at how to expect the date stamp and index from the remote file. Any help will be appreciated. Curt
pushing csv vaules into hash
I am really stuck here. I need to split values from a csv value and push them into an array, then perform a routine for all of them in a foreach statement. In this example I am reading an email address, a username and a password and needing to send each user listed in the csv a mail to the email address with the message containing their username and password. I am successful in reading the lines of the file and the ability to iterate through them with once they are in the array, but then how do I get them into variables to be used by the sub? Again in this example, I need to create a variable ($to) from the first value, a username ($username) from the second value and a password($password) from the third value. Those variables will obviously be different for each iteration through the foreach. code## #!/usr/bin/perl use strict; use Mail::Sendmail; my $csvfile = 'test.csv'; my $currentline; open (IN, "<$csvfile") or die "Couldn't open input CSV file: $!"; my @data = sort ; my $lastline = ' '; foreach $currentline(@data){ next if $currentline eq $lastline; my @split = split(',',$currentline); foreach my $split (@split){ &MailPass; } } close IN; sub MailPass{ my $to = ""; my $username = ""; my $password = ""; my $from = "[EMAIL PROTECTED]"; my $subject = "Your Login Information"; my %mail = (To=> $to, From=> $from, Subject=> $subject Message => "Your username is $username and your password is $password", ); sendmail(%mail) or die $Mail::Sendmail::error; } end code Thanks for the help! Curt
RE: mail list via script
-Original Message- From: Ryan Frantz [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 07, 2006 11:28 AM To: Curt Shaffer; beginners@perl.org Subject: RE: mail list via script > -Original Message- > From: Curt Shaffer [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 07, 2006 11:21 AM > To: Ryan Frantz; beginners@perl.org > Subject: RE: mail list via script > > > > -Original Message- > From: Ryan Frantz [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 07, 2006 11:09 AM > To: Curt Shaffer; beginners@perl.org > Subject: RE: mail list via script > > > > > -Original Message- > > From: Curt Shaffer [mailto:[EMAIL PROTECTED] > > Sent: Tuesday, March 07, 2006 11:06 AM > > To: beginners@perl.org > > Subject: mail list via script > > > > I have a need to mail 1000 users their usernames and passwords, this > will > > be > > a 1 time thing. I was thinking that I could just do some sort of > foreach > > routine but I can't see how that will work when they will all be > > different. > > I then thought a hash with the usernames and passwords would be OK, > but > > then > > how to I link the proper email account with the proper hash value. I > am > > Since every key in a hash has to be unique, and every email address is > unique, use the email address as the key in your hash: > > my %mailAccounts = ( > [EMAIL PROTECTED] => 'abc123', > [EMAIL PROTECTED] => 'def456', > ... > ); > > > not > > asking for the step by step here but if anyone has some direction for > me I > > would appreciate it and figure it out from there. > > > > > > > > > > > > Thanks > > > > > > > > Curt > > > > > > > > > > > > > Thanks for the response! The problem I have with this solution is I need > to > send both a username and a password (i.e. two values) per email. Can I add > another value to the hash like this: [EMAIL PROTECTED] => > 'abc123','321cba',? > You may want to look into more complex data structures (hash of arrays, etc.). See the following: perldoc perldata perldoc perldsc In all honesty, however, you may be better served by a simpler approach such a comma-delimited file that you can parse: # emailAddress,username,password [EMAIL PROTECTED],johnsmith,abc123 [EMAIL PROTECTED],janesmith,def456 ry Thanks! That was actually another delema, that I didn't want to write all of those out. We do have a comma-delimited file with this information and that would be much easier! Thanks for all of your help -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
RE: mail list via script
-Original Message- From: Ryan Frantz [mailto:[EMAIL PROTECTED] Sent: Tuesday, March 07, 2006 11:09 AM To: Curt Shaffer; beginners@perl.org Subject: RE: mail list via script > -Original Message- > From: Curt Shaffer [mailto:[EMAIL PROTECTED] > Sent: Tuesday, March 07, 2006 11:06 AM > To: beginners@perl.org > Subject: mail list via script > > I have a need to mail 1000 users their usernames and passwords, this will > be > a 1 time thing. I was thinking that I could just do some sort of foreach > routine but I can't see how that will work when they will all be > different. > I then thought a hash with the usernames and passwords would be OK, but > then > how to I link the proper email account with the proper hash value. I am Since every key in a hash has to be unique, and every email address is unique, use the email address as the key in your hash: my %mailAccounts = ( [EMAIL PROTECTED] => 'abc123', [EMAIL PROTECTED] => 'def456', ... ); > not > asking for the step by step here but if anyone has some direction for me I > would appreciate it and figure it out from there. > > > > > > Thanks > > > > Curt > > > > > > Thanks for the response! The problem I have with this solution is I need to send both a username and a password (i.e. two values) per email. Can I add another value to the hash like this: [EMAIL PROTECTED] => 'abc123','321cba',? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
mail list via script
I have a need to mail 1000 users their usernames and passwords, this will be a 1 time thing. I was thinking that I could just do some sort of foreach routine but I can't see how that will work when they will all be different. I then thought a hash with the usernames and passwords would be OK, but then how to I link the proper email account with the proper hash value. I am not asking for the step by step here but if anyone has some direction for me I would appreciate it and figure it out from there. Thanks Curt
RE: regular expression in a variable
Thank you all so much. And thank you timothy for the clarification. I do use the use strict. I don't tend to use the warnings much, guess maybe I should at least during development. Thanks Again! Curt -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 5:50 PM To: Curt Shaffer; beginners@perl.org Subject: RE: regular expression in a variable If you declare a variable with my(), it only exists within the current scope (NOTE: always add 'use strict' and 'use warnings' whenever you can at the top of your scripts). What you'll have to do is declare a variable outside of the brackets. You could even use a subroutine, like the one below. When it matches, I'm returning the name of the file. If I get through the whole loop without matching, I'm returning 0 to indicate that it failed. # use strict; use warnings; my $file; if($file = GetTestFileName()){ print "I got it! $file\n"; }else{ print "Failed to locate test file!\n"; } sub GetTestFileName{ opendir(DIR,".") or die("Couldn't open the current directory!\n"); my @files = readdir(DIR); foreach my $testfile(sort @files){ if($testfile =~ /(.*test.*)/i){ return $testfile; } } return 0; } ## -Original Message- From: Curt Shaffer [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 1:11 PM To: Timothy Johnson; beginners@perl.org Subject: RE: regular expression in a variable That appears to work! The part I am stuck on is how to I take that value (which would now be $file in your example) and put it into a variable that I can use through the rest of the script. When I then try to use $file outside of that routine, it is no longer the same value. I really appreciate your help! smime.p7s Description: S/MIME cryptographic signature
RE: regular expression in a variable
Yes I am trying to collect the file (the result will only produce 1 match) And I need that into a variable that can be used for the processing. -Original Message- From: Wagner, David --- Senior Programmer Analyst --- WGO [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 4:19 PM To: Curt Shaffer; Timothy Johnson; beginners@perl.org Subject: RE: regular expression in a variable Curt Shaffer wrote: > That appears to work! The part I am stuck on is how to I take that > value (which would now be $file in your example) and put it into a > variable that I can use through the rest of the script. When I then > try to use $file outside of that routine, it is no longer the same > value. > > I really appreciate your help! > > So are you trying to collect all the files up front and then go through the processing? You already have the test in the loop and could just write a subroutine and pass it $file and do all your work there. If you want to hold on to those fiels which match your criteria, then use another array to capture as in @matchedfiles = grep( /*.test.*/, @files ); Either way, you have the data in place or the other. Wags ;) > > -Original Message- > From: Timothy Johnson [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 28, 2006 3:47 PM > To: Curt Shaffer; beginners@perl.org > Subject: RE: regular expression in a variable > > > So what part are you stuck on then? It looks like the first > suggestion gets you the $filename you want. All you have to do after > that is move > it. > > (you can change it so it isn't looking in the current directory with > the opendir line, but if you do, don't forget that you can't move the > files > by filename alone, you must add the path as a prefix) > > -Original Message- > From: Curt Shaffer [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 28, 2006 12:42 PM > To: Timothy Johnson; beginners@perl.org > Subject: RE: regular expression in a variable > > Thanks for the response. Let me try to clear things up. The second > solution > will not work for me because the other parts of the filename will be > unknown. The only part I know will always be in the filename is "test" > (only > an example). > > So the full story is this: > > I need to look in a directory to see if a file with "test" in the name > exists. If it does I need to move that file to a staging directory to > be sftp'd out to a vendor. The manner in which I am doing that is to > move > the > file named $filename (whose value is the result of the regex match) to > the > staging directory. Then sftp the $filename to the appropriate place. > > Does that help a bit? If not I apologize. > > Curt > > -Original Message- > From: Timothy Johnson [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 28, 2006 3:30 PM > To: Curt Shaffer; beginners@perl.org > Subject: RE: regular expression in a variable > > > You're not being very clear what it is you're trying to do. I can see > two ways of interpreting this. > > Regular expressions are mostly for checking the format of text to see > if certain conditions "match". You might be asking how to do this: > > > > use strict; > use warnings; > opendir(DIR,".") or die("Couldn't open the current directory!\n"); > my @files = readdir(DIR); > foreach my $file(sort @files){ >if($file =~ /(.*test.*)/i){ > print "MATCH: $file\n"; >} > } > > # > > You can also use the $1 variable to capture the last text string that > matched the part of the regular expression between the parentheses. > > > If, on the other hand, you're trying to generate file names, then > regular expressions aren't what you're looking for. > > my $prefix = "123"; > my $postfix = "456"; > my $filename = $prefix."test".$postfix; > print $filename."\n"; > > > > > -Original Message- > From: Curt Shaffer [mailto:[EMAIL PROTECTED] > Sent: Tuesday, February 28, 2006 12:20 PM > To: beginners@perl.org > Subject: regular expression in a variable > > I need to set a variable to a filename where only 1 section of the > file > is > static. > > For example: > > $filename =~ /test/; > > Where the following: > > Print "$filename\n"; > > Would produce: > > 123test456.txt *** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. *** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
RE: regular expression in a variable
That appears to work! The part I am stuck on is how to I take that value (which would now be $file in your example) and put it into a variable that I can use through the rest of the script. When I then try to use $file outside of that routine, it is no longer the same value. I really appreciate your help! -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 3:47 PM To: Curt Shaffer; beginners@perl.org Subject: RE: regular expression in a variable So what part are you stuck on then? It looks like the first suggestion gets you the $filename you want. All you have to do after that is move it. (you can change it so it isn't looking in the current directory with the opendir line, but if you do, don't forget that you can't move the files by filename alone, you must add the path as a prefix) -Original Message----- From: Curt Shaffer [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 12:42 PM To: Timothy Johnson; beginners@perl.org Subject: RE: regular expression in a variable Thanks for the response. Let me try to clear things up. The second solution will not work for me because the other parts of the filename will be unknown. The only part I know will always be in the filename is "test" (only an example). So the full story is this: I need to look in a directory to see if a file with "test" in the name exists. If it does I need to move that file to a staging directory to be sftp'd out to a vendor. The manner in which I am doing that is to move the file named $filename (whose value is the result of the regex match) to the staging directory. Then sftp the $filename to the appropriate place. Does that help a bit? If not I apologize. Curt -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 3:30 PM To: Curt Shaffer; beginners@perl.org Subject: RE: regular expression in a variable You're not being very clear what it is you're trying to do. I can see two ways of interpreting this. Regular expressions are mostly for checking the format of text to see if certain conditions "match". You might be asking how to do this: use strict; use warnings; opendir(DIR,".") or die("Couldn't open the current directory!\n"); my @files = readdir(DIR); foreach my $file(sort @files){ if($file =~ /(.*test.*)/i){ print "MATCH: $file\n"; } } # You can also use the $1 variable to capture the last text string that matched the part of the regular expression between the parentheses. If, on the other hand, you're trying to generate file names, then regular expressions aren't what you're looking for. my $prefix = "123"; my $postfix = "456"; my $filename = $prefix."test".$postfix; print $filename."\n"; -Original Message- From: Curt Shaffer [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 12:20 PM To: beginners@perl.org Subject: regular expression in a variable I need to set a variable to a filename where only 1 section of the file is static. For example: $filename =~ /test/; Where the following: Print "$filename\n"; Would produce: 123test456.txt -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
RE: regular expression in a variable
Thanks for the response. Let me try to clear things up. The second solution will not work for me because the other parts of the filename will be unknown. The only part I know will always be in the filename is "test" (only an example). So the full story is this: I need to look in a directory to see if a file with "test" in the name exists. If it does I need to move that file to a staging directory to be sftp'd out to a vendor. The manner in which I am doing that is to move the file named $filename (whose value is the result of the regex match) to the staging directory. Then sftp the $filename to the appropriate place. Does that help a bit? If not I apologize. Curt -Original Message- From: Timothy Johnson [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 3:30 PM To: Curt Shaffer; beginners@perl.org Subject: RE: regular expression in a variable You're not being very clear what it is you're trying to do. I can see two ways of interpreting this. Regular expressions are mostly for checking the format of text to see if certain conditions "match". You might be asking how to do this: use strict; use warnings; opendir(DIR,".") or die("Couldn't open the current directory!\n"); my @files = readdir(DIR); foreach my $file(sort @files){ if($file =~ /(.*test.*)/i){ print "MATCH: $file\n"; } } # You can also use the $1 variable to capture the last text string that matched the part of the regular expression between the parentheses. If, on the other hand, you're trying to generate file names, then regular expressions aren't what you're looking for. my $prefix = "123"; my $postfix = "456"; my $filename = $prefix."test".$postfix; print $filename."\n"; -Original Message- From: Curt Shaffer [mailto:[EMAIL PROTECTED] Sent: Tuesday, February 28, 2006 12:20 PM To: beginners@perl.org Subject: regular expression in a variable I need to set a variable to a filename where only 1 section of the file is static. For example: $filename =~ /test/; Where the following: Print "$filename\n"; Would produce: 123test456.txt -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>
regular expression in a variable
I need to set a variable to a filename where only 1 section of the file is static. For example: $filename =~ /test/; Where the following: Print "$filename\n"; Would produce: 123test456.txt The only way I see this being possible is with regular expressions but I can't for the life of me figure out the syntax I need. Any help appreciated! Curt