Re:confused about reference
> Message du 31/10/08 04:08 > De : "Richard Lee" > A : "Perl Beginners" > Copie à : > Objet : confused about reference > > > > I was just testing some reference and while trying out below I am trying > to understand below > > @{$yahoo->{yahoo}}... I can see that this is pointing to 0,1,3 > by running the code. > But I am trying to really understand whether this is trying to say since > value of 'yahoo' is array put @ at the front? > or @ is there because it's array slice?? > Can someone explain this? > > Also, %{$base[0]}, trying to understand this. > According to the tutorial, > > %base referenced is %{$base} > > what is the difference between %{$base[0]} vs %{$base}[0] %{$base}[0] is just a syntax error. $hash->{$base}[0] is effective syntax. For %{$base[0]}. $base[0] is an anonymous hash (or hash reference), %{...} will derefer it. Jeff. http://home.arcor.de/pangj/ Créez votre adresse électronique [EMAIL PROTECTED] 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.
Re: confused about reference
Richard Lee wrote: I was just testing some reference and while trying out below I am trying to understand below @{$yahoo->{yahoo}}... I can see that this is pointing to 0,1,3 by running the code. But I am trying to really understand whether this is trying to say since value of 'yahoo' is array put @ at the front? or @ is there because it's array slice?? Can someone explain this? @{$yahoo->{yahoo}} has @ on it because it's value of yahoo is reference. Is this right? Also, %{$base[0]}, trying to understand this. According to the tutorial, %base referenced is %{$base} what is the difference between %{$base[0]} vs %{$base}[0] Are we here talking about first being hash reference which first item is array reference vs second one is hash reference's first item ? This one, I cannot figure it out thank you. #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $yahoo = { 'yahoo' => [ 0, 1, 3], 'msn' => [ 12, 32, 44] }; print Dumper($yahoo); print "\n\n\n\n\n\n"; print "${$yahoo}{yahoo}[0]\n"; # prints 0 print "$yahoo->{yahoo}[0]\n";# prints 0 print "@{$yahoo->{yahoo}}\n";# prints 0,1,3 print "%{$yahoo->{yahoo}}\n";# print %{ARRAY(0x832e8c4)} -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re:confused about reference
> Message du 31/10/08 04:08 > De : "Richard Lee" > A : "Perl Beginners" > Copie à : > Objet : confused about reference > > > > I was just testing some reference and while trying out below I am trying > to understand below > > @{$yahoo->{yahoo}}... I can see that this is pointing to 0,1,3 > by running the code. > But I am trying to really understand whether this is trying to say since > value of 'yahoo' is array put @ at the front? > Here $yahoo is a hash reference (or say it's pointing to an anonymous hash), you could declare it as $yahoo = {}; $yahoo->{yahoo} points to a hash value whose key is 'yahoo'. This value is an anonymous array, say it's $yahoo->{yahoo} = [1,2,3]. so @{$yahoo->{yahoo}} will derefer the anonymous array, you will get an array of (1,2,3) finally. Jeff. http://home.arcor.de/pangj/ Créez votre adresse électronique [EMAIL PROTECTED] 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.
confused about reference
I was just testing some reference and while trying out below I am trying to understand below @{$yahoo->{yahoo}}... I can see that this is pointing to 0,1,3 by running the code. But I am trying to really understand whether this is trying to say since value of 'yahoo' is array put @ at the front? or @ is there because it's array slice?? Can someone explain this? Also, %{$base[0]}, trying to understand this. According to the tutorial, %base referenced is %{$base} what is the difference between %{$base[0]} vs %{$base}[0] Are we here talking about first being hash reference which first item is array reference vs second one is hash reference's first item ? thank you. #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my $yahoo = { 'yahoo' => [ 0, 1, 3], 'msn' => [ 12, 32, 44] }; print Dumper($yahoo); print "\n\n\n\n\n\n"; print "${$yahoo}{yahoo}[0]\n"; # prints 0 print "$yahoo->{yahoo}[0]\n";# prints 0 print "@{$yahoo->{yahoo}}\n";# prints 0,1,3 print "%{$yahoo->{yahoo}}\n";# print %{ARRAY(0x832e8c4)} -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to put a global variable in a package, accessible to users of that package?
On Thu, 2008-10-30 at 23:43 +, Rob Dixon wrote: > mrstevegross wrote: > > > > I have a package named "Foo" in which I want to define some package- > > level constants (such as $VAR="soemval"). I want those constants > > available to users of package Foo, so the following code would work: > > > > === foo.pl === > > package foo; > > use constant VAR => "someval"; > > > > === bar.pl === > > use foo; > > print $foo::VAR; > > > > It doesn't appear to be working; it compiles ok, but it prints > > nothing. I thought it would print "someval". > > The code as you show it will not work at all. The line > > use foo; > > will throw the error "Can't locate foo.pm in @INC" because you have > incorrectly > named it foo.pl. > > To get your program working, save the module as 'foo.pm' instead, and change > its > contents to > > use strict; > use warnings; > > package foo; > > our $VAR = "someval"; > > 1; Some additional notes: 1) The naming convention in Perl is to start packages and their file with a capital letter. Hence the file is Foo.pm and: package Foo; 2) Perl does not have true constants. When you `use constant` you actually create a sub that returns a value. This: use constant VAR => "someval"; is the same as: sub VAR { return "someval"; } Since it is a sub, you can call it using a fully qualified name. The following call method is checked at compile time (and will give an error if you misspell something): use Foo; Foo->VAR; The following is checked at run time (and it will not give an error, if any, until the code is executed): use Foo; Foo::VAR; The compile time methodology is preferred. Only use the run-time one if you are dynamically creating subs. 3) You can download the module Readonly from CPAN http://search.cpan.org/ It creates variables that cannot be changed. 4) Global 'my' variables cannot be accessed outside of the file their are defined in. They also cannot be exported via the Exporter module. Define them with `our` or `use vars`. All `our` globals can be accessed with their fully qualified name, even if they are not exported. See: perldoc perlvar perldoc perlmod perldoc perlmodlib -- Just my 0.0002 million dollars worth, Shawn The map is not the territory, the dossier is not the person, the model is not reality, and the universe is indifferent to your beliefs. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: How to put a global variable in a package, accessible to users of that package?
mrstevegross wrote: > > I have a package named "Foo" in which I want to define some package- > level constants (such as $VAR="soemval"). I want those constants > available to users of package Foo, so the following code would work: > > === foo.pl === > package foo; > use constant VAR => "someval"; > > === bar.pl === > use foo; > print $foo::VAR; > > It doesn't appear to be working; it compiles ok, but it prints > nothing. I thought it would print "someval". The code as you show it will not work at all. The line use foo; will throw the error "Can't locate foo.pm in @INC" because you have incorrectly named it foo.pl. To get your program working, save the module as 'foo.pm' instead, and change its contents to use strict; use warnings; package foo; our $VAR = "someval"; 1; HTH, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
How to put a global variable in a package, accessible to users of that package?
I have a package named "Foo" in which I want to define some package- level constants (such as $VAR="soemval"). I want those constants available to users of package Foo, so the following code would work: === foo.pl === package foo; use constant VAR => "someval"; === bar.pl === use foo; print $foo::VAR; It doesn't appear to be working; it compiles ok, but it prints nothing. I thought it would print "someval". Any ideas? Thanks, --Steve -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re:signal processing INT or TERM
> Message du 30/10/08 10:45 > De : "icarus" > A : beginners@perl.org > Copie à : > Objet : signal processing INT or TERM > > > perl 5.8.2 > OS: AIX fully POSIX compliant > > my script moves files from one dir to another. > When I want my script to stop, should I pass it along the signal INT > or TERM? > > INT just interrupts the script. It finishes whatever it's processing > and then it's done. > > TERM on the other hand, just sends a TERMination signal, waits a few > seconds, then KILLs the program. TERM is more common I guess when > starting/stopping unix shell scripts in the init dir. > > My fear is that if I pass the TERM signal, maybe the system will chop > off the files that are being moved on the fly. The "few seconds" are > unpredictable in value at least on my system. So the system might say > 'it's been too long, let's kill it." > > Any thoughts? Is there a "perlish" way to do it? > SIGTERM and SIGINT are almost the same usage. See 'man 8 kill' and look for signals. You may want to redefine the POSIX signal handlers. See also L. Stein's "Network programming with Perl", that will give the full details. Jeff. http://home.arcor.de/pangj/ Créez votre adresse électronique [EMAIL PROTECTED] 1 Go d'espace de stockage, anti-spam et anti-virus intégrés.
RE: Hi all
From: Anusha Krishna chand > I have to make my back button of the browser disable ... can any one > help me in doing that using perl script... > Thanks in advance > Anusha Krishnachand The quickest way to do that in most browsers is right click on the toolbar, select customize and remove the button from the bar. If you mean disable it on browsers used to view your pages, you can't do that and shouldn't even try. That button is a basic feature of the browser and should always be available. I do know there is a javascript trick that works on some browsers, but I consider that a bug that should have been fixed long ago. I also file bug reports on any site that I notice interfering with the use of back and forward buttons. Another option is to add 'target="_blank"' attribute to the anchor to open the page in a new tab or window. Bob McConnell -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: matching elements from array and print the results line by line from log file
slow_leaner wrote: On Oct 28, 2:51 pm, [EMAIL PROTECTED] (Andy Cravens) wrote: -Original Message- From: slow_leaner [mailto:[EMAIL PROTECTED] Sent: Tue 10/28/2008 11:58 AM To: [EMAIL PROTECTED] Subject: matching elements from array and print the results line by line from log file Hi, I have a list of element in array that I would like to match the pattern in logs file. I have hard time take element from array and matching it. More then weeks now and don't know where to find in man page. please help me. Here is my code. #!/usr/bin/perl -w open ( FILE, " /var/log/cisco.log " ) || die "can't open cisco.log file!"; @cisco.log = ; close (FILE); @array = qw( BPDUGUARD FAN_FAIL ); # more then 2 elements in array while (<@cisco.log>){ foreach $line (@array){ $_ =~ $line; #DOESN'T WORK AND I AM STUCK.. print "$_\n"; #WANT TO PRINT THAT MATCH } } __END__ thanks for your help -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]://learn.perl.org/ Try this and let me know if it works... #!/usr/bin/perl -w open ( FILE, "/var/log/cisco.log " ) || die "can't open cisco.log file!"; @cisco = ; close (FILE); @array = qw( BPDUGUARD FAN_FAIL ); # more then 2 elements in array foreach $line (@cisco) { foreach $string (@array) { if ($line =~ $string) { print "$line $string"; } } } exit; __ thanks Andy. it works. But here is my gold. 1. i have 2 logs file that i would like to appending into one big @LOGFILE. spend 3 hours already and still.. 2. lists of element in @array that will match the line in above @LOGFILE. 3. then email it to me with the line that match (still reading the man page.) As you are appending 2 files to create 1:- I'm sure something similar is available under unix, but as I use windows, I go to a DOS(Command) prompt copy file1+file2 file3 et voila. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
beginners@perl.org
Rob Coops wrote: What the (? Thank you so much, Regards Brent -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
beginners@perl.org
> -Original Message- > From: Brent Clark [mailto:[EMAIL PROTECTED] > Sent: 30 October 2008 09:57 > To: beginners@perl.org > Subject: regex for & > > Hiya > > I have three sentences. > > This is a nice hotel. > The view & food is good. > We are at the Victoria & Alfred Hotel. > > I need a perl regex / code to not print out sentence 2 (basically fail). > > This is what I so far. > > print $_ if $_ !~ /\&|Victoria \&/ig; > > Im struggling to get this right. > > TIA. > #! /usr/bin/perl use warnings; use strict ; while () { print $_ if $_ !~ /\&|Victoria \&/ig; } __DATA__ This is a nice hotel. The view & food is good. We are at the Victoria & Alfred Hotel. Information in this email including any attachments may be privileged, confidential and is intended exclusively for the addressee. The views expressed may not be official policy, but the personal views of the originator. If you have received it in error, please notify the sender by return e-mail and delete it from your system. You should not reproduce, distribute, store, retransmit, use or disclose its contents to anyone. Please note we reserve the right to monitor all e-mail communication through our internal and external networks. SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and are used under licence. British Sky Broadcasting Limited (Registration No. 2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited (Registration No. 2340150) are direct or indirect subsidiaries of British Sky Broadcasting Group plc (Registration No. 2247735). All of the companies mentioned in this paragraph are incorporated in England and Wales and share the same registered office at Grant Way, Isleworth, Middlesex TW7 5QD. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
beginners@perl.org
On Thu, Oct 30, 2008 at 10:56 AM, Brent Clark <[EMAIL PROTECTED]>wrote: > Hiya > > I have three sentences. > > This is a nice hotel. > The view & food is good. > We are at the Victoria & Alfred Hotel. > > I need a perl regex / code to not print out sentence 2 (basically fail). > > This is what I so far. > > print $_ if $_ !~ /\&|Victoria \&/ig; > > Im struggling to get this right. > > TIA. > > Regards > Brent Clark > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > Hi Brent, I just tried this and found that you where nrealy there. #!/usr/local/bin/perl use strict; use warnings; my @text = ('This is a nice hotel.', 'The view & food is good.', 'We are at the Victoria & Alfred Hotel.'); foreach ( @text ) { print $_ . "\n" if ( $_ !~ /(?http://perldoc.perl.org/perlretut.html#Backreferences> for more information on how this works. Reagrds, Rob
beginners@perl.org
>>-Original Message- >>From: Brent Clark [mailto:[EMAIL PROTECTED] >>Sent: Thursday, October 30, 2008 10:57 AM >>To: beginners@perl.org >>Subject: regex for & >> >>Hiya >> >>I have three sentences. >> >>This is a nice hotel. >>The view & food is good. >>We are at the Victoria & Alfred Hotel. >> >>I need a perl regex / code to not print out sentence 2 (basically fail). >> >>This is what I so far. >> >>print $_ if $_ !~ /\&|Victoria \&/ig; >> >>Im struggling to get this right. >> >>TIA. >> >>Regards >>Brent Clark This should work if ($_ !~ /^We are at the Victoria \& Alfred Hotel./) { Marco -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: matching elements from array and print the results line by line from log file
On Oct 28, 2:51 pm, [EMAIL PROTECTED] (Andy Cravens) wrote: > -Original Message- > From: slow_leaner [mailto:[EMAIL PROTECTED] > Sent: Tue 10/28/2008 11:58 AM > To: [EMAIL PROTECTED] > Subject: matching elements from array and print the results line by line from > log file > > Hi, > I have a list of element in array that I would like to match the > pattern in logs file. I have hard time take element from array and > matching it. More then weeks now and don't know where to find in man > page. please help me. Here is my code. > > #!/usr/bin/perl -w > open ( FILE, " /var/log/cisco.log " ) || die "can't open cisco.log > file!"; > @cisco.log = ; > close (FILE); > > @array = qw( BPDUGUARD FAN_FAIL ); # more then 2 elements in array > > while (<@cisco.log>){ > foreach $line (@array){ > $_ =~ $line; #DOESN'T WORK AND I AM STUCK.. >print "$_\n"; #WANT TO PRINT THAT MATCH > } > } > > __END__ > thanks for your help > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED]://learn.perl.org/ > > Try this and let me know if it works... > > #!/usr/bin/perl -w > open ( FILE, "/var/log/cisco.log " ) || die "can't open cisco.log file!"; > @cisco = ; > close (FILE); > @array = qw( BPDUGUARD FAN_FAIL ); # more then 2 elements in array > foreach $line (@cisco) { > foreach $string (@array) { > if ($line =~ $string) { print "$line $string"; } > } > } > exit; __ thanks Andy. it works. But here is my gold. 1. i have 2 logs file that i would like to appending into one big @LOGFILE. spend 3 hours already and still.. 2. lists of element in @array that will match the line in above @LOGFILE. 3. then email it to me with the line that match (still reading the man page.) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
beginners@perl.org
Hiya I have three sentences. This is a nice hotel. The view & food is good. We are at the Victoria & Alfred Hotel. I need a perl regex / code to not print out sentence 2 (basically fail). This is what I so far. print $_ if $_ !~ /\&|Victoria \&/ig; Im struggling to get this right. TIA. Regards Brent Clark -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
signal processing INT or TERM
perl 5.8.2 OS: AIX fully POSIX compliant my script moves files from one dir to another. When I want my script to stop, should I pass it along the signal INT or TERM? INT just interrupts the script. It finishes whatever it's processing and then it's done. TERM on the other hand, just sends a TERMination signal, waits a few seconds, then KILLs the program. TERM is more common I guess when starting/stopping unix shell scripts in the init dir. My fear is that if I pass the TERM signal, maybe the system will chop off the files that are being moved on the fly. The "few seconds" are unpredictable in value at least on my system. So the system might say 'it's been too long, let's kill it." Any thoughts? Is there a "perlish" way to do it? -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Hi all
Hi ... I have to make my back button of the browser disable ... can any one help me in doing that using perl script... Thanks in advance Anusha Krishnachand
Re: Efficient way of comparing items in an array
Hi Dave, Dave Tang wrote: On Thu, 30 Oct 2008 16:04:31 +1000, Dave Tang <[EMAIL PROTECTED]> wrote: I have written the following code but I wish I could think of a much better way of achieving my output. Any tips and suggestions will be greatly appreciated! Thanks in advance. Oops I mean (I wrote the code in my email) and sorry for the double post. my $prev = 'NULL'; my $first = ''; for (my $i = 0; $i < scalar(@array); ++$i){ if ($prev eq 'NULL'){ $prev = $array[$i]; $first = $array[$i]; } else { if ($array[$i] == $prev + 1){ $prev = $array[$i]; } else { print "$first - $prev\n"; $prev = $array[$i]; $first = $array[$i]; } } } print "$first - $prev\n"; __END__ You have a list of sorted numbers and you're making a single pass through it; you are also looking at each number at most once [excluding the starting end-point which you keep track of]. So, I can't think of a way to make it much faster. Your first if statement can probably be removed. You only use it once, right? In the very beginning. You might want to set $prev and $first to $array[0], and start the for loop from $i = 1. Or do you have NULLs in your data? These are co-ordinates in a genome or something? If your data file is so large that you find that your program is too slow, you might want to try a non-scripting language (C or C++). Another more likely problem if your data file is too big is that the slowdown might be due to disk accesses -- and if so, there isn't much I can think of which you can do. Beyond these thoughts, I can't think of anything else...maybe someone else can? Ray -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Reading from multiple sockets.
>>> From: Peter Scott [mailto:[EMAIL PROTECTED] >>> Subject: Re: Reading from multiple sockets. > >> On Tue, 21 Oct 2008 12:53:53 +0200, Kammen van, Marco, Springer SBM NL >> wrote: >> I'm pretty new to working with sockets in perl, looked around for days >> for a proper solution for my IRC/DCC problem but couldn't find one. >>>Yeah I was planning to add another Perl programming book to my list >>>Thanks for all hints so far... I've got the following to work now using >>>IO::Select >>>Properly send & receive to and from server. >>>I can esablish a DCC connection over additional socket, but then I only >>>get the data from the DCC socket, and no-longer the data from the server >>>socket, untill the DCC socket is closed. >>Never mind... I think i fixed it >>Dunno if its the proper way but hey it works! >>$con = IO::Socket::INET->new(PeerAddr=>"$server", >> PeerPort=>"$port", >> Proto=>'tcp', >> Timeout=>'30') || print "Error! $!\n"; >>$select = IO::Select->new(); >>$select->add($con); >>while(@ready = $select->can_write) { >> for $socket (@ready) { >>#The DCC Connection >>if($socket == $dcc) { >> $talk = <$dcc>; >> print $talk; >> #The Server Connection >>} elsif ($socket == $con) { >> $answer = <$con>; >> print $answer; >> # Stufff >> if ($answer =~ /:(.*)\!.* PRIVMSG $me :\001DCC CHAT chat (\d+) ( >>+\d+)\001\r\n/) { >>print "Received dcc from $1 with $2 and $3\n"; >>$dcc = IO::Socket::INET->new(PeerAddr=>"$2", >> PeerPort=>"$3", >> Proto=>'tcp', >> Timeout=>'30') || print "Error! >>+ $!\n"; >>print $dcc "Please Enter Your Password!\n"; >>$select->add($dcc); >> } >>} else { >> print "Dunno?\n"; >> exit 1; >>} >> } >>} It looked like it worked but keep ending up in some kind of lock As soon as the second socket kicks in things go wrong It's a shame there are tons of pieces of code for IRC thingies, but none of a fully functional one including DCC connections (without using additional modules). Any help in the right direction is appreciated... (and yes I'm still waiting on my Perl networking book!) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/