Re: Perl script: where was I executed from?
Hi, I am not sure that I completely understand your question (for example, what does it mean to run a script "dynamically or not"). You could retrieve the list of processes from OS to try to figure out how was the script ran, but it is a bit messy. Just maybe: maybe you want to see whether the script is printing to a terminal or not and which terminal. For example, something like: if (-t STDOUT) { print "this is tty\n" } else { print "not tty\n" } will give different output when you run directly in terminal, or if you redirect the standard output to a file. On Sat, 21 Nov 2020, wagsworld48 via beginners wrote: > The only problem I was trying to determine was could i know if I was running > from BBEdit dynamically or not? That > was the question. No problem, just could I know what environment I was > running in. The output was a the Unix output > log which up to the last update automatically came to the front of the BBEdit > windows. No longer does. Whether it is > Perl or another scripting language, I was trying to make it easier as one > tested. > > So that is what I was after... ;) > > WagsWorld World of Perl > Hebrews 4:15 > Ph D:(408)914-1341 > Ph M:(408)761-7391 > On Nov 21, 2020, 21:10 -0800, Uri Guttman , wrote: > On 11/21/20 10:32 PM, wagsworl...@yahoo.com wrote: > Well, up until this last update is BBEdit, when a script was run > while > in BBEdit, the Unix log file would automatically come to the fore > front. Now it stays hidden. > > > that doesn't sound like a perl problem. what log file? there are many on > a unix system. and why/how would a log file come to the front? it would > have to be open in some program. > > A gentleman on the BBEdit mail list gave an osasctipt that one > can > execute from within the script bring executed. But sometimes I run > from terminal session, so don’t want to tell BBEdit to do > something is > not required. Hence where am I and from that know what to do... > > again, i don't see the actual problem you are having. is it really a > perl issue? would the problem exist if you did your program in another > language? that is a good question to determine if it is a language vs > system issue. i don't see a perl problem in your comments. > > thanx, > > uri > > > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl script: where was I executed from?
On 11/22/20 12:33 AM, wagsworl...@yahoo.com wrote: The only problem I was trying to determine was could i know if I was running from BBEdit dynamically or not? That was the question. No problem, just could I know what environment I was running in. The output was a the Unix output log which up to the last update automatically came to the front of the BBEdit windows. No longer does. Whether it is Perl or another scripting language, I was trying to make it easier as one tested. that still is an XY problem. you are asking for X (know where perl is being spawned) when your actual problem is Y (getting the log file to pop up). they are not the same problem. if you just need to see the log file, run a tail -f command in a shell window and it will show you all the new log stuff as it happens. that is not a perl problem. thanx, uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl script: where was I executed from?
The only problem I was trying to determine was could i know if I was running from BBEdit dynamically or not? That was the question. No problem, just could I know what environment I was running in. The output was a the Unix output log which up to the last update automatically came to the front of the BBEdit windows. No longer does. Whether it is Perl or another scripting language, I was trying to make it easier as one tested. So that is what I was after... ;) WagsWorld World of Perl Hebrews 4:15 Ph D:(408)914-1341 Ph M:(408)761-7391 On Nov 21, 2020, 21:10 -0800, Uri Guttman , wrote: > On 11/21/20 10:32 PM, wagsworl...@yahoo.com wrote: > > Well, up until this last update is BBEdit, when a script was run while > > in BBEdit, the Unix log file would automatically come to the fore > > front. Now it stays hidden. > > > > that doesn't sound like a perl problem. what log file? there are many on > a unix system. and why/how would a log file come to the front? it would > have to be open in some program. > > > A gentleman on the BBEdit mail list gave an osasctipt that one can > > execute from within the script bring executed. But sometimes I run > > from terminal session, so don’t want to tell BBEdit to do something is > > not required. Hence where am I and from that know what to do... > again, i don't see the actual problem you are having. is it really a > perl issue? would the problem exist if you did your program in another > language? that is a good question to determine if it is a language vs > system issue. i don't see a perl problem in your comments. > > thanx, > > uri >
Re: Perl script: where was I executed from?
On 11/21/20 10:32 PM, wagsworl...@yahoo.com wrote: Well, up until this last update is BBEdit, when a script was run while in BBEdit, the Unix log file would automatically come to the fore front. Now it stays hidden. that doesn't sound like a perl problem. what log file? there are many on a unix system. and why/how would a log file come to the front? it would have to be open in some program. A gentleman on the BBEdit mail list gave an osasctipt that one can execute from within the script bring executed. But sometimes I run from terminal session, so don’t want to tell BBEdit to do something is not required. Hence where am I and from that know what to do... again, i don't see the actual problem you are having. is it really a perl issue? would the problem exist if you did your program in another language? that is a good question to determine if it is a language vs system issue. i don't see a perl problem in your comments. thanx, uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl script: where was I executed from?
Well, up until this last update is BBEdit, when a script was run while in BBEdit, the Unix log file would automatically come to the fore front. Now it stays hidden. A gentleman on the BBEdit mail list gave an osasctipt that one can execute from within the script bring executed. But sometimes I run from terminal session, so don’t want to tell BBEdit to do something is not required. Hence where am I and from that know what to do... Thoughts??? ;) WagsWorld World of Perl Hebrews 4:15 Ph D:(408)914-1341 Ph M:(408)761-7391 On Nov 21, 2020, 18:09 -0800, Uri Guttman , wrote: > On 11/21/20 7:42 PM, wagsworld48 via beginners wrote: > > It was a good idea, but that gives me zsh which is what in this case > > BBEdit uses to execute the script. So with your code of $ENV, then I > > looked at the variables within ENV and picked one that was there for > > BBEdit and not there in a normal terminal run. Know other ways, but > > this at least is one way to accomplish the task.. > ok, i am smelling an XY problem here. why do you need to know from where > the perl was executed? in general processes don't know the path of their > parent process. one way around this is to pass a special value to the > perl process (via argument or env) that tells the perl of its origin. > > but a bigger question is, why do you need/want to know this? what > difference will it make to the perl process? > > thanx, > > uri > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > >
Re: Perl script: where was I executed from?
On 11/21/20 7:42 PM, wagsworld48 via beginners wrote: It was a good idea, but that gives me zsh which is what in this case BBEdit uses to execute the script. So with your code of $ENV, then I looked at the variables within ENV and picked one that was there for BBEdit and not there in a normal terminal run. Know other ways, but this at least is one way to accomplish the task.. ok, i am smelling an XY problem here. why do you need to know from where the perl was executed? in general processes don't know the path of their parent process. one way around this is to pass a special value to the perl process (via argument or env) that tells the perl of its origin. but a bigger question is, why do you need/want to know this? what difference will it make to the perl process? thanx, uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Perl script: where was I executed from?
It was a good idea, but that gives me zsh which is what in this case BBEdit uses to execute the script. So with your code of $ENV, then I looked at the variables within ENV and picked one that was there for BBEdit and not there in a normal terminal run. Know other ways, but this at least is one way to accomplish the task.. Thanks much for getting the mind going. I appreciate the thought and it did help... ;) WagsWorld World of Perl Hebrews 4:15 Ph D:(408)914-1341 Ph M:(408)761-7391 On Nov 21, 2020, 16:03 -0800, sisyphus , wrote: > Perhaps: > perl -le 'print $ENV{SHELL}' > > Cheers, > Rob > > > On Sun, Nov 22, 2020 at 8:00 AM wagsworld48 via beginners > > wrote: > > > Mind is blank, but want to know if started with say BBEdit or bash or ? > > > > > > Probably very simple, but at this point, no idea... ;) > > > > > > WagsWorld > > > World of Perl > > > Hebrews 4:15 > > > Ph D:(408)914-1341 > > > Ph M:(408)761-7391
Re: Perl script: where was I executed from?
Perhaps: perl -le 'print $ENV{SHELL}' Cheers, Rob On Sun, Nov 22, 2020 at 8:00 AM wagsworld48 via beginners < beginners@perl.org> wrote: > Mind is blank, but want to know if started with say BBEdit or bash or ? > > Probably very simple, but at this point, no idea... ;) > > WagsWorld > World of Perl > Hebrews 4:15 > Ph D:(408)914-1341 > Ph M:(408)761-7391 >
Perl script: where was I executed from?
Mind is blank, but want to know if started with say BBEdit or bash or ? Probably very simple, but at this point, no idea... ;) WagsWorld World of Perl Hebrews 4:15 Ph D:(408)914-1341 Ph M:(408)761-7391
Re: can I use some kind of binary string?
Hi, On Sat, 18 May 2019 14:02:46 +0200 hwilmer wrote: > On 5/16/19 9:56 PM, Shlomi Fish wrote: > > On Thu, 16 May 2019 13:13:16 +0200 > > hwilmer wrote: > > > >> On 5/11/19 11:07 AM, Shlomi Fish wrote: > [...] > >>>> So I would want to use something like > >>>> > >>>> > >>>> my $binary_data = `curl -k "https://www.example.com/some.jpg"`; > >>>> > >>> > >>> Perl distinguishes between 8-bit/binary strings and unicode ones. See > >>> https://perldoc.perl.org/perlunitut.html . > >> > >> What kind of string do I get when using backticks like in the above > >> example? > > [...] > > Perhaps use open "-|" with an encoding - see > > https://perldoc.perl.org/functions/binmode.html . > > I didn't know I could do that ... I tried it and it works, too. > Nice. > >>> Note however that you should see > >>> https://perl-begin.org/uses/web-automation/ and use a module instead of > >>> trapping curl.exe's output. Perl has bindings to libcurl too if that is > >>> what you want. > >> > >> First I tried to use WWW::Mechanize, and that failed because it can't > >> deal witch the self-signed certificates the web server is using. I > >> couldn't find anywhere in the documentation how to allow such > >> certificates. Otherwise it seemed to be able to do what I wanted. > >> > > > > See > > https://stackoverflow.com/questions/47662461/how-to-accept-self-signed-certificates-with- > > > lwpuseragent > > That gives an error: 'Bareword "IO::Socket::SSL::SSL_VERIFY_NONE" not > allowed while "strict subs" in use ...'. But this works: > >my $ua = LWP::UserAgent->new( > max_size => $MAX_DOWNLOAD_SIZE, > ssl_opts => { > ssl_verify => 0, > verify_hostname => 0 > } > ); > Great! Thanks for the tip. -- - Shlomi Fish http://www.shlomifish.org/ https://is.gd/MQHVF3 - The Atom Text Editor edits a 2,000,001B file The Bajoran scholars have positively identified Benjamin Sisko as The Emissary. They also positively identified the NSA headquarters as The Dungeon. — http://www.shlomifish.org/humour/bits/facts/NSA/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: can I use some kind of binary string?
On 5/16/19 9:56 PM, Shlomi Fish wrote: On Thu, 16 May 2019 13:13:16 +0200 hwilmer wrote: On 5/11/19 11:07 AM, Shlomi Fish wrote: [...] So I would want to use something like my $binary_data = `curl -k "https://www.example.com/some.jpg"`; Perl distinguishes between 8-bit/binary strings and unicode ones. See https://perldoc.perl.org/perlunitut.html . What kind of string do I get when using backticks like in the above example? > [...] Perhaps use open "-|" with an encoding - see https://perldoc.perl.org/functions/binmode.html . I didn't know I could do that ... I tried it and it works, too. Note however that you should see https://perl-begin.org/uses/web-automation/ and use a module instead of trapping curl.exe's output. Perl has bindings to libcurl too if that is what you want. First I tried to use WWW::Mechanize, and that failed because it can't deal witch the self-signed certificates the web server is using. I couldn't find anywhere in the documentation how to allow such certificates. Otherwise it seemed to be able to do what I wanted. See https://stackoverflow.com/questions/47662461/how-to-accept-self-signed-certificates-with- lwpuseragent That gives an error: 'Bareword "IO::Socket::SSL::SSL_VERIFY_NONE" not allowed while "strict subs" in use ...'. But this works: my $ua = LWP::UserAgent->new( max_size => $MAX_DOWNLOAD_SIZE, ssl_opts => { ssl_verify => 0, verify_hostname => 0 } ); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: can I use some kind of binary string?
On Thu, 16 May 2019 13:13:16 +0200 hwilmer wrote: > On 5/11/19 11:07 AM, Shlomi Fish wrote: > > Hi hwilmer, > > > > On Fri, 10 May 2019 19:09:50 +0200 > > hwilmer wrote: > > > >> Hi, > >> > >> I would like to use curl to retrieve an image from a web server which I > >> want to store in a table in a mariadb database without downloading the > >> image to a file. For this application, I do not want to store > >> references to files stored in some file system instead. > >> > >> So I would want to use something like > >> > >> > >> my $binary_data = `curl -k "https://www.example.com/some.jpg"`; > >> > > > > Perl distinguishes between 8-bit/binary strings and unicode ones. See > > https://perldoc.perl.org/perlunitut.html . > > What kind of string do I get when using backticks like in the above > example? One that perl considers as a text string I could use stuff > like uc or lc on, or as a binary string I could use pack or unpack on? > Variables are without types, so there is no way to tell. If I was using > curl to receive a text string, how would I know which encoding is being > used? For all I know that could depend on the machine my program is > running on after lots of factors I would never know about. And this > same encoding could happen to the image data. > > Why would I use pack or unpack on the image data curl puts into the > string? Do I need to worry that somewhere --- like in my program or in > some method DBI provides or somewhere else --- some kind of string > transformation might take place that damages the image data? Is there a > way to tell perl that this is actually not a string but some binary data > that must not be transformed or encoded? > > So far, it's working, but that could be just luck ... > Perhaps use open "-|" with an encoding - see https://perldoc.perl.org/functions/binmode.html . > > Note however that you should see https://perl-begin.org/uses/web-automation/ > > and use a module instead of trapping curl.exe's output. Perl has bindings to > > libcurl too if that is what you want. > > First I tried to use WWW::Mechanize, and that failed because it can't > deal witch the self-signed certificates the web server is using. I > couldn't find anywhere in the documentation how to allow such > certificates. Otherwise it seemed to be able to do what I wanted. > See https://stackoverflow.com/questions/47662461/how-to-accept-self-signed-certificates-with-lwpuseragent > Using curl via the library bindings is somewhat going to lengths I would > rather avoid. > -- - Shlomi Fish http://www.shlomifish.org/ http://youtu.be/xZLwtc9x4yA - Anime in Real Life!! (Parody) Well, one thing I can tell you about parenthood is that such things can progress from figurative to literal, extremely quickly. — http://www.shlomifish.org/humour/Summerschool-at-the-NSA/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: can I use some kind of binary string?
On 5/11/19 11:07 AM, Shlomi Fish wrote: Hi hwilmer, On Fri, 10 May 2019 19:09:50 +0200 hwilmer wrote: Hi, I would like to use curl to retrieve an image from a web server which I want to store in a table in a mariadb database without downloading the image to a file. For this application, I do not want to store references to files stored in some file system instead. So I would want to use something like my $binary_data = `curl -k "https://www.example.com/some.jpg"`; Perl distinguishes between 8-bit/binary strings and unicode ones. See https://perldoc.perl.org/perlunitut.html . What kind of string do I get when using backticks like in the above example? One that perl considers as a text string I could use stuff like uc or lc on, or as a binary string I could use pack or unpack on? Variables are without types, so there is no way to tell. If I was using curl to receive a text string, how would I know which encoding is being used? For all I know that could depend on the machine my program is running on after lots of factors I would never know about. And this same encoding could happen to the image data. Why would I use pack or unpack on the image data curl puts into the string? Do I need to worry that somewhere --- like in my program or in some method DBI provides or somewhere else --- some kind of string transformation might take place that damages the image data? Is there a way to tell perl that this is actually not a string but some binary data that must not be transformed or encoded? So far, it's working, but that could be just luck ... Note however that you should see https://perl-begin.org/uses/web-automation/ and use a module instead of trapping curl.exe's output. Perl has bindings to libcurl too if that is what you want. First I tried to use WWW::Mechanize, and that failed because it can't deal witch the self-signed certificates the web server is using. I couldn't find anywhere in the documentation how to allow such certificates. Otherwise it seemed to be able to do what I wanted. Using curl via the library bindings is somewhat going to lengths I would rather avoid. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: can I use some kind of binary string?
Hi hwilmer, On Fri, 10 May 2019 19:09:50 +0200 hwilmer wrote: > Hi, > > I would like to use curl to retrieve an image from a web server which I > want to store in a table in a mariadb database without downloading the > image to a file. For this application, I do not want to store > references to files stored in some file system instead. > > So I would want to use something like > > > my $binary_data = `curl -k "https://www.example.com/some.jpg"`; > Perl distinguishes between 8-bit/binary strings and unicode ones. See https://perldoc.perl.org/perlunitut.html . Note however that you should see https://perl-begin.org/uses/web-automation/ and use a module instead of trapping curl.exe's output. Perl has bindings to libcurl too if that is what you want. > > The image then needs to be inserted into a LONGBLOB field via DBI in > such a way that the image can be restored as it was. > > Will string conversions or something prevent this from working? > > What is the usual way to do this? It is certainly not ideal to have no > check on the amount of data that might be retrieved from the web server, > regardless whether I save it to an intermediate file or not. > > To make things more difficult, the web server is using a self-signed > certificate. > -- - Shlomi Fish http://www.shlomifish.org/ http://www.shlomifish.org/humour/bits/New-versions-of-the-GPL/ He who reinvents the wheel will likely design a square wheel and spend a year trying to figure out why it doesn’t work properly. — Nadav Har’El, http://www.shlomifish.org/humour.html Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
can I use some kind of binary string?
Hi, I would like to use curl to retrieve an image from a web server which I want to store in a table in a mariadb database without downloading the image to a file. For this application, I do not want to store references to files stored in some file system instead. So I would want to use something like my $binary_data = `curl -k "https://www.example.com/some.jpg"`; The image then needs to be inserted into a LONGBLOB field via DBI in such a way that the image can be restored as it was. Will string conversions or something prevent this from working? What is the usual way to do this? It is certainly not ideal to have no check on the amount of data that might be retrieved from the web server, regardless whether I save it to an intermediate file or not. To make things more difficult, the web server is using a self-signed certificate. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Device::SerialPort Am I Missing Something?
David Precious writes: > Instead of assigning the result of $port->lookfor to $c, you've created > a new lexically-scoped $c (with "my $c") which exists only within that > loop body execution - after the execution, it goes away, and the $c the > loop is looking for, at a higher scope, will still be empty. > > I imagine things might change if you remove the "my" from that > assignment, so that you're assigning the result to the $c that the loop > condition is looking at. Of course! I didn't even give that a second thought. I removed 'my' and wrote a test loop for another old P.C. I have here which sends the string 0 1 2 3 4 5 6 7 8 9 followed by a carriage return every 2 seconds. I am using a kermit script for that and a null-modem cable to send to ttyS0 on the system running the now-working perl app. I put the digit '8' in the are_match expression and now, when I run the perl application, I see 0 1 2 3 4 5 6 7 so it is breaking the string on 8 which is precisely what I need for the test to work. Now I can go on and do something useful. I was being dense, here, I think. Thank you very much. Martin McCormick -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Device::SerialPort Am I Missing Something?
On Fri, 03 Nov 2017 15:12:15 -0500 "Martin McCormick" wrote: > What is needed, however, is to be able to use the are_match > feature which fills a buffer with data until a pattern is > detected which stops the read and gives you a series of bytes > that may not necessarily end with a newline or carriage return. > > I have never yet gotten anything like the following to > work: > > #!/usr/bin/perl -w > use strict; > #use warnings::unused; > use File::Basename; > use File::Copy; > use File::Spec; > use Time::Local; > use Device::SerialPort; > > sub comm {#serialport > > my $dev = "/dev/ttyS0"; > my $c = ""; > my $port = Device::SerialPort->new("$dev"); > $port->baudrate(9600); $port->databits(8); $port->parity("none"); > $port->stopbits(1); $port->handshake("none"); >$port->write_settings; > > until ("" ne $c) { > my $c= $port->lookfor; > print ("$c\n") if $c; > } > return; > }#serial port [...] > I have tried it with and without an are_match pattern and > it just roars along, looping endlessly at the lookfor statement > and never picking up anything. Instead of assigning the result of $port->lookfor to $c, you've created a new lexically-scoped $c (with "my $c") which exists only within that loop body execution - after the execution, it goes away, and the $c the loop is looking for, at a higher scope, will still be empty. I imagine things might change if you remove the "my" from that assignment, so that you're assigning the result to the $c that the loop condition is looking at. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Device::SerialPort Am I Missing Something?
The perldoc for Device::SerialPort states that the unix version is based on the Windows serial port module and a few details are different or not supported but the important parts are said to work. Strangely enough, the only thing I have gotten to work as described is the $port->input directive. It does echo strings being sent to the serial device. Here is code that works: #!/usr/bin/perl -w use strict; use File::Basename; use File::Copy; use File::Spec; use Device::SerialPort; sub comm {#serialport my $dev = "/dev/ttyS0"; my $char = ""; my $port = Device::SerialPort->new ("$dev"); $port->baudrate(9600) || die "failed setting baudrate"; $port->parity("none")|| die "failed setting parity"; $port->databits(8) || die "failed setting databits"; $port->handshake("none") || die "failed setting handshake"; $port->write_settings|| die "no settings"; #$port->save("~/etc/testport"); #that doesn't do anything. while (1) { if (my $c = $port->input) { print ("$c\n"); } } return; }#serial port comm; That does cause input strings to be sent to standard output. What is needed, however, is to be able to use the are_match feature which fills a buffer with data until a pattern is detected which stops the read and gives you a series of bytes that may not necessarily end with a newline or carriage return. I have never yet gotten anything like the following to work: #!/usr/bin/perl -w use strict; #use warnings::unused; use File::Basename; use File::Copy; use File::Spec; use Time::Local; use Device::SerialPort; sub comm {#serialport my $dev = "/dev/ttyS0"; my $c = ""; my $port = Device::SerialPort->new("$dev"); $port->baudrate(9600); $port->databits(8); $port->parity("none"); $port->stopbits(1); $port->handshake("none"); $port->write_settings; until ("" ne $c) { my $c= $port->lookfor; print ("$c\n") if $c; } return; }#serial port comm; The perldoc for Device::SerialPort indicates that are_match will default to a newline or carriage return if one does not have another pattern in an are_match statement such as $port->are_match("8");# possible end strings The $c string should then contain characters except for the number 8 which would be the end of that string. I have tried it with and without an are_match pattern and it just roars along, looping endlessly at the lookfor statement and never picking up anything. What am I missing? Sincere thanks for any constructive suggestions. Martin McCormick WB5AGZ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Thu, Aug 3, 2017 at 3:29 PM hw wrote: > David Mertens wrote: > It is nonsense to logically negate a string, and it is nonsense to convert > undefined values into 'false'. Negating strings is a well defined operation in Perl 5. The following values in Perl 5 are false: undef, 0, 0.0, "", "0", and the empty list. Negation turns any value that is true into a false value (PL_sv_no) and any value that is false into a true value (PL_sv_yes). > Either are neither false, nor true. > You are coming to Perl 5 with assumptions that do not hold water here. As I said above (and in earlier emails), there are two strings ("0" and "") that are false and all other strings are true. The undef value is also false. > For undefined values, there is no way of deciding whether they are true or > false > because they are undefined. > That would be true if Perl 5 used a trinary logic system, but if you peruse the documentation, you will find no mention of it. The undef value in Perl 5 is not analogous to NULL in SQL. It is merely a sentinel value (sort of like NULL in C, but with no defined value, so it doesn't take up a value that could otherwise be used). Perl 5 happily coerces this sentinel value into 0 or "" depending on context (though it will throw a warning if use the warnings pragma). Perl 5 has no boolean type. Instead it has true values and false values. This works very well in most cases. It would be nearly impossible to retrofit a boolean type at this point and maintain backwards compatibility, so the chances of you getting what you want is very unlikely. If this is a real problem for you, then I suggest you chose a language that more accurately reflects the way you expect it to work. If you are required to use Perl 5 by your work, I suggest you find a job that lets you use the language you want to use. Life is too short to beat your head against the wall and you don't seem to be listening to the people here.
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Thu, Aug 03, 2017 at 09:27:42PM +0200, hw wrote: > > It is nonsense to logically negate a string, and it is nonsense to convert > undefined values into 'false'. Either are neither false, nor true. > > For undefined values, there is no way of deciding whether they are true or > false > because they are undefined. > > When you convert undefined values to false, then you must also convert false > to undefined values. Logic dictates that otherwise undefined values are > not equal to undefined values. Yet perl claims that they are: > > perl -e 'print "true\n" if(undef == undef);' > perl -e 'print "true\n" if(0 == undef);' > > Both is just wrong. The value 0 is defined to the point where you can´t > define > it any more. If you try to fight against Perl, or any language, you will have an unsatisfying experience. The trick is to work with the language. Then programming becomes productive and enjoyable, the sun shines, ponies frolic through meadows, and unicorns graze contentedly beneath rainbows. -- Paul Johnson - p...@pjcj.net http://www.pjcj.net -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
David Mertens wrote: On Thu, Jul 6, 2017 at 11:05 PM, mailto:sisyph...@optusnet.com.au>> wrote: Perl is highly unusual in that the operator, not the operand, dictates the context. Good point - and one that I hadn't got around to noticing. Therefore, the '!' operator has to be set up to either: a) operate always in numeric context; or b) operate always in string context; or c) operate always in both contexts (as per the current behaviour). Having an ambivalent '!' operator (where it alternates between a) and b), according to the operand's flags) is therefore not an option. If we wanted an operator for "logical string negation" and an operator for "logical numeric negation" we would need 2 different operators. Have I got that somewhere near right ? Cheers, Rob Yes, I think so. Of course, that was one of Larry's design decisions, and I think it was a good one. If you really care to have operand-dependent behavior, you can create a class that overloads the operator and carry your data around in instances of that class. Also, boolean works beyond simple string and numeric context. In particular, boolean context coerces undefined values to false without issuing warnings, and it's not clear how an undefined value would operate under "logical string negation" and "logical numeric negation". It is nonsense to logically negate a string, and it is nonsense to convert undefined values into 'false'. Either are neither false, nor true. For undefined values, there is no way of deciding whether they are true or false because they are undefined. When you convert undefined values to false, then you must also convert false to undefined values. Logic dictates that otherwise undefined values are not equal to undefined values. Yet perl claims that they are: perl -e 'print "true\n" if(undef == undef);' perl -e 'print "true\n" if(0 == undef);' Both is just wrong. The value 0 is defined to the point where you can´t define it any more. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Thu, Jul 6, 2017 at 11:05 PM, wrote: > Perl is highly unusual in that the operator, not the operand, dictates the >> context. >> > > Good point - and one that I hadn't got around to noticing. > > Therefore, the '!' operator has to be set up to either: > a) operate always in numeric context; > or > b) operate always in string context; > or > c) operate always in both contexts (as per the current behaviour). > > Having an ambivalent '!' operator (where it alternates between a) and b), > according to the operand's flags) is therefore not an option. > > If we wanted an operator for "logical string negation" and an operator for > "logical numeric negation" we would need 2 different operators. > > Have I got that somewhere near right ? > > Cheers, > Rob > Yes, I think so. Of course, that was one of Larry's design decisions, and I think it was a good one. If you really care to have operand-dependent behavior, you can create a class that overloads the operator and carry your data around in instances of that class. Also, boolean works beyond simple string and numeric context. In particular, boolean context coerces undefined values to false without issuing warnings, and it's not clear how an undefined value would operate under "logical string negation" and "logical numeric negation". David -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
Hi! You don't need logical string negotiation and logical number negotiation. You just need logical negotioation. Using `!` operator to convert non-empty string to empty string is wrong, so as using `!` operator to convert not zero number to zero. `!` operator is for logical operations only. You don't want to use screwdriver to hammer in nails, just because you can do it. And just because perl has More Than One Way To Do It (aka TIMTOWTDI), it doesn't mean you should do it this way. * * 07.07.17 6:05, sisyph...@optusnet.com.au пишет: From: David Mertens Sent: Friday, July 07, 2017 12:07 PM To: Sisyphus Cc: Chas. Owens ; hw ; Perl Beginners Subject: Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' On Thu, Jul 6, 2017 at 9:12 PM, wrote: I find it a little surprising that use of the '!' operator is all that's needed to add the stringification stuff: ... If the '!' operator didn't do that, then I believe the OP would be seeing precisely what he expects. So ... why should the '!' operator *not* respect the string/numeric context of the operand ? Perl is highly unusual in that the operator, not the operand, dictates the context. Good point - and one that I hadn't got around to noticing. Therefore, the '!' operator has to be set up to either: a) operate always in numeric context; or b) operate always in string context; or c) operate always in both contexts (as per the current behaviour). Having an ambivalent '!' operator (where it alternates between a) and b), according to the operand's flags) is therefore not an option. If we wanted an operator for "logical string negation" and an operator for "logical numeric negation" we would need 2 different operators. Have I got that somewhere near right ? Cheers, Rob
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
From: David Mertens Sent: Friday, July 07, 2017 12:07 PM To: Sisyphus Cc: Chas. Owens ; hw ; Perl Beginners Subject: Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' On Thu, Jul 6, 2017 at 9:12 PM, wrote: I find it a little surprising that use of the '!' operator is all that's needed to add the stringification stuff: ... If the '!' operator didn't do that, then I believe the OP would be seeing precisely what he expects. So ... why should the '!' operator *not* respect the string/numeric context of the operand ? Perl is highly unusual in that the operator, not the operand, dictates the context. Good point - and one that I hadn't got around to noticing. Therefore, the '!' operator has to be set up to either: a) operate always in numeric context; or b) operate always in string context; or c) operate always in both contexts (as per the current behaviour). Having an ambivalent '!' operator (where it alternates between a) and b), according to the operand's flags) is therefore not an option. If we wanted an operator for "logical string negation" and an operator for "logical numeric negation" we would need 2 different operators. Have I got that somewhere near right ? Cheers, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Thu, Jul 6, 2017 at 9:12 PM, wrote: > I find it a little surprising that use of the '!' operator is all that's > needed to add the stringification stuff: > > ... > > If the '!' operator didn't do that, then I believe the OP would be seeing > precisely what he expects. > > So ... why should the '!' operator *not* respect the string/numeric > context of the operand ? > Perl is highly unusual in that the *operator*, not the operand, dictates the context. We know tha $foo eq $bar forces $foo and $bar into string context and then compares them as strings, and $foo == $bar forces numeric context. I personally find this to be a hallmark of Perl, a way in which it Does What I Mean, where what I mean is indicated by the operator that I chose to use. Assignment like $result = !$i does not provide a context, but the negation operator does---boolean---and so we get a result that is boolean true or false, both of which are represented by special kinds of dual-vars, as was already explained. David -- "Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." -- Brian Kernighan
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
From: Chas. Owens Sent: Friday, July 07, 2017 12:34 AM To: hw ; beginners@perl.org Subject: Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' On Thu, Jul 6, 2017 at 9:38 AM hw wrote: Chas. Owens wrote: $i started off as an IV, but gets promoted to a PVIV by being used in string context. I find it a little surprising that use of the '!' operator is all that's needed to add the stringification stuff: C:\>perl -MDevel::Peek -le "$i=0; Dump($i); Dump(!$i);" SV = IV(0x93ece0) at 0x93ece4 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 0 SV = PVNV(0xb0a934) at 0xb03090 REFCNT = 2147483644 FLAGS = (IOK,NOK,POK,READONLY,pIOK,pNOK,pPOK) IV = 1 NV = 1 PV = 0xb0330c "1"\0 CUR = 1 LEN = 12 If the '!' operator didn't do that, then I believe the OP would be seeing precisely what he expects. So ... why should the '!' operator *not* respect the string/numeric context of the operand ? Why does it insist on logically negating *both* the numeric and string slots of the variable, even when those slots are initially unset ? Maybe it's just that that's the way it has always been done - or maybe there's a more convincing reason ? Cheers, Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Thu, Jul 6, 2017 at 9:33 AM hw wrote: > False and true are genuinely numeric. You can´t say for a string > whether it is true or false; it is a string. > This is not a true statement in Perl. All values in Perl can be true or false. And the prototypical true and false values, PL_sv_yes and PL_sv_no, are dualvars that hold multiple values (string, int, and double). These values are returned by the various logical operators (and any other XS code that wants to use them). The following values in Perl are false: the empty list, undef, "", 0, 0.0, and "0". All other values are true. These give you different results, and that is just wrong. I did > assign a /number/ to $i and never a string. No, you assigned the result of the negation operator which returns PL_sv_yes if the operand is false (see above for the list of false values) or PL_sv_no if the operand is true. Since 0 is false, !0 return PL_sv_yes (which contains "1", 1, and 1.0). Since since PL_sv_yes is true, !!0 returns PL_sv_no (which contains the values "", 0, and 0.0). If you want to ensure the result is an integer value 0 or 1, then you need to say: $i = defined $i ? 0+!!$i : 0; The venus secret operator (0+) forces the result to be an integer or double (depending on what $i contained). Another option is to use the int operator: $i = defined $i ? int !!0 : 0;
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Thu, Jul 6, 2017 at 9:38 AM hw wrote: > Chas. Owens wrote: > > > > > > On Sat, Jul 1, 2017, 12:44 Shlomi Fish shlo...@shlomifish.org>> wrote: > > > > Hi Shawn! > > > > On Sat, 1 Jul 2017 11:32:30 -0400 > > Shawn H Corey mailto:shawnhco...@gmail.com>> > wrote: > > > > > !!$i which is !(!(0)) which is !(1) which is 0 > > > > > > > I suspect !1 returns an empty string in scalar context. > > > > > > !1 returns PL_sv_no (an internal scalar variable). It is a dualvar that > contains the empty string, the int 0 and the double 0.0. depending on the > context the value is used in, it will be one of those values. > > > > Many people think it is an empty string because the print function > forces string context. > > > > > perl -e 'my $i =0; $i = defined($i) ? (!!$i) : 0; use Data::Dumper; print > Dumper($i);' > > > A printing function should not force a context but use the context it is > operating in. > > How do you print something without having a string context enforced upon > you? > String context will always be force by printing (you don't print integers, you print characters). If you want to ensure that a dualvar uses the double (or integer if the double doesn't exist), you use the venus secret operator (so named because it looks like the Greek symbol for Venus ♀): 0+. Secret operators aren't really operators (or secret), but are just a set of operators and arguments that are used idiomatically. for example: perl -E 'my $i = !!0; print "\$i as a string: [$i]\n\$i as an int: [", 0+$i, "]\n"' $i as a string: [] $i as an int: [0] Data::Dumper is not the best way to see what a variable holds if you care about types. The Devel::Peek module gives you a much better picture, but you do need to know a bit about perl (ie the interpreter) to understand it (because Perl, the language, doesn't care about types): perl -MDevel::Peek -E 'my $i = !!0; Dump $i' SV = PVNV(0x7f88488036b0) at 0x7f884882a0b8 REFCNT = 1 FLAGS = (IOK,NOK,POK,pIOK,pNOK,pPOK) IV = 0 NV = 0 PV = 0x7f8848405180 ""\0 CUR = 0 LEN = 10 Here we can see that $i is a PVNV, that is it holds a string (Pointer Value) and a number (Number Value). The flags IOK, NOK, and POK tell us that the IV (integer), NV (double), and PV (string) portions are all safe to use. Now let's look at $i after the venus secret operator runs: perl -MDevel::Peek -E 'my $i = 0+!!0; Dump $i' SV = IV(0x7febe102a0a8) at 0x7febe102a0b8 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 0 Now we can see that $i is an IV and it only has an IV section (and the corresponding flag). But be careful, you can taint this be using $i in a string context: perl -MDevel::Peek -E 'my $i = 0+!!0; "$i"; Dump $i' SV = PVIV(0x7fd841004e20) at 0x7fd841002eb8 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 0 PV = 0x7fd84070b3f0 "0"\0 CUR = 1 LEN = 10 >From this we can see that using an IV in string context will cause perl to cache the string version of the IV. But note that, unlike PL_sv_no, the string value is actually "0" not "". This is mostly an issue for serialization (JSON in particular). Just for illustration of why the flags are important: perl -MDevel::Peek -E 'my $i = 0+!!0; Dump $i; "$i"; Dump $i; $i++; Dump $i' SV = IV(0x7f941402a0a8) at 0x7f941402a0b8 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 0 SV = PVIV(0x7f941402c020) at 0x7f941402a0b8 REFCNT = 1 FLAGS = (IOK,POK,pIOK,pPOK) IV = 0 PV = 0x7f9413c04eb0 "0"\0 CUR = 1 LEN = 10 SV = PVIV(0x7f941402c020) at 0x7f941402a0b8 REFCNT = 1 FLAGS = (IOK,pIOK) IV = 1 PV = 0x7f9413c04eb0 "0"\0 CUR = 1 LEN = 10 $i started off as an IV, but gets promoted to a PVIV by being used in string context. Then math is done on the IV portion which invalidates the cached string, so the POK flag is removed. The cached value of "0" is still present in the variable, but properly behaving code will not access it (only XS code could even see it). Just don't ask me about the pIOK, pNOK, and pPOK flags, 'cause I have never understood what they represent.
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
X Dungeness wrote: It's about what unary ! (bang operator) does to the operand Here's the dissonance: perl -E '$x=0; say "x=$x"; $x = !!$x; say "x=$x"' x=0 x= It behaves as you expect until you "bang" it twice. I found a good explanation in the Camel: "Unary ! performs logical negation, that is "not". The value of a negated operand is true (1) if the operand is false (numeric 0,string "0", the null string, or undefined) and false ("") if the operand is true." So double banging 0 yields "". That doesn´t explain how and why a numerical value is converted into a string. It could be something else than the operator doing this. In any case, which sane programmer would expect a bug like this. perl -e 'my $i = 1; $i = defined($i) ? (!$i) : 0; use Data::Dumper; print Dumper($i);' $VAR1 = ''; Logical negations do not involve turning numbers into strings. If they do, they are either something else or buggy. How do you enforce a numerical context? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
Chas. Owens wrote: On Sat, Jul 1, 2017, 12:44 Shlomi Fish mailto:shlo...@shlomifish.org>> wrote: Hi Shawn! On Sat, 1 Jul 2017 11:32:30 -0400 Shawn H Corey mailto:shawnhco...@gmail.com>> wrote: > !!$i which is !(!(0)) which is !(1) which is 0 > I suspect !1 returns an empty string in scalar context. !1 returns PL_sv_no (an internal scalar variable). It is a dualvar that contains the empty string, the int 0 and the double 0.0. depending on the context the value is used in, it will be one of those values. Many people think it is an empty string because the print function forces string context. perl -e 'my $i =0; $i = defined($i) ? (!!$i) : 0; use Data::Dumper; print Dumper($i);' A printing function should not force a context but use the context it is operating in. How do you print something without having a string context enforced upon you? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
Shlomi Fish wrote: Hi hw! Please see http://www.shlomifish.org/philosophy/computers/netiquette/email/reply-to-list.html . On Sat, 1 Jul 2017 19:15:22 +0200 hw wrote: Shlomi Fish wrote: Hi Shawn! On Sat, 1 Jul 2017 11:32:30 -0400 Shawn H Corey wrote: On Sat, 1 Jul 2017 17:27:02 +0200 hw wrote: Hi, can someone please explain this: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' i: Particularly: + Why doesn´t it print 1? Because !!$i is zero + How is this not a bug? Nope, no bug. + What is being printed here? !!$i which is !(!(0)) which is !(1) which is 0 I suspect !1 returns an empty string in scalar context. What would be the reasoning for a numerical operator turning numerical values into (empty) strings within a numerical context? "!" is not a numerical operator - it is a *logical* operator. If one passes a true value to it one gets a false value. False and true are genuinely numeric. You can´t say for a string whether it is true or false; it is a string. Else, one gets a true value. See http://perldoc.perl.org/perlop.html . If used in a numerical context, false values are treated as zeroes, but not all of them are zeroes in other contexts. There is no other context involved here than a numerical one. There is also no reason to implicitly change the context to any other one, like a string context. perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print $i;' perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; printf("%d", $i);' perl -e 'my $i = undef; $i = defined($i) ? (!!$i) : 0; print $i;' These give you different results, and that is just wrong. I did assign a /number/ to $i and never a string. Regards, Shlomi + How do you do what I intended in perl? How do we know what you intend? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
It's about what unary ! (bang operator) does to the operand Here's the dissonance: perl -E '$x=0; say "x=$x"; $x = !!$x; say "x=$x"' x=0 x= It behaves as you expect until you "bang" it twice. I found a good explanation in the Camel: "Unary ! performs logical negation, that is "not". The value of a negated operand is true (1) if the operand is false (numeric 0,string "0", the null string, or undefined) and false ("") if the operand is true." So double banging 0 yields "". On Sat, Jul 1, 2017 at 12:54 PM, John Harris wrote: > What are these emails really about? > > On Jul 1, 2017 2:42 PM, "Chas. Owens" wrote: > >> >> >> On Sat, Jul 1, 2017, 12:44 Shlomi Fish wrote: >> >>> Hi Shawn! >>> >>> On Sat, 1 Jul 2017 11:32:30 -0400 >>> Shawn H Corey wrote: >>> >>> > !!$i which is !(!(0)) which is !(1) which is 0 >>> > >>> >>> I suspect !1 returns an empty string in scalar context. >>> >> >> !1 returns PL_sv_no (an internal scalar variable). It is a dualvar that >> contains the empty string, the int 0 and the double 0.0. depending on the >> context the value is used in, it will be one of those values. >> >> Many people think it is an empty string because the print function forces >> string context. >> >>>
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
What are these emails really about? On Jul 1, 2017 2:42 PM, "Chas. Owens" wrote: > > > On Sat, Jul 1, 2017, 12:44 Shlomi Fish wrote: > >> Hi Shawn! >> >> On Sat, 1 Jul 2017 11:32:30 -0400 >> Shawn H Corey wrote: >> >> > !!$i which is !(!(0)) which is !(1) which is 0 >> > >> >> I suspect !1 returns an empty string in scalar context. >> > > !1 returns PL_sv_no (an internal scalar variable). It is a dualvar that > contains the empty string, the int 0 and the double 0.0. depending on the > context the value is used in, it will be one of those values. > > Many people think it is an empty string because the print function forces > string context. > >>
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Sat, Jul 1, 2017, 12:44 Shlomi Fish wrote: > Hi Shawn! > > On Sat, 1 Jul 2017 11:32:30 -0400 > Shawn H Corey wrote: > > > !!$i which is !(!(0)) which is !(1) which is 0 > > > > I suspect !1 returns an empty string in scalar context. > !1 returns PL_sv_no (an internal scalar variable). It is a dualvar that contains the empty string, the int 0 and the double 0.0. depending on the context the value is used in, it will be one of those values. Many people think it is an empty string because the print function forces string context. >
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
Hi hw! Please see http://www.shlomifish.org/philosophy/computers/netiquette/email/reply-to-list.html . On Sat, 1 Jul 2017 19:15:22 +0200 hw wrote: > Shlomi Fish wrote: > > Hi Shawn! > > > > On Sat, 1 Jul 2017 11:32:30 -0400 > > Shawn H Corey wrote: > > > >> On Sat, 1 Jul 2017 17:27:02 +0200 > >> hw wrote: > >> > >>> > >>> Hi, > >>> > >>> can someone please explain this: > >>> > >>> > >>> perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' > >>> i: > >>> > >>> > >>> Particularly: > >>> > >>> > >>> + Why doesn´t it print 1? > >> > >> Because !!$i is zero > >> > >>> > >>> + How is this not a bug? > >> > >> Nope, no bug. > >> > >>> > >>> + What is being printed here? > >> > >> !!$i which is !(!(0)) which is !(1) which is 0 > >> > > > > I suspect !1 returns an empty string in scalar context. > > What would be the reasoning for a numerical operator turning > numerical values into (empty) strings within a numerical context? > "!" is not a numerical operator - it is a *logical* operator. If one passes a true value to it one gets a false value. Else, one gets a true value. See http://perldoc.perl.org/perlop.html . If used in a numerical context, false values are treated as zeroes, but not all of them are zeroes in other contexts. Regards, Shlomi > > > > > >>> > >>> + How do you do what I intended in perl? > >>> > >> > >> How do we know what you intend? > >> > >> > > > > > > > -- - Shlomi Fish http://www.shlomifish.org/ UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/ Real programmers don’t write workarounds. They tell their users to upgrade their software. — http://www.shlomifish.org/humour.html Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
Hi Shawn! On Sat, 1 Jul 2017 11:32:30 -0400 Shawn H Corey wrote: > On Sat, 1 Jul 2017 17:27:02 +0200 > hw wrote: > > > > > Hi, > > > > can someone please explain this: > > > > > > perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' > > i: > > > > > > Particularly: > > > > > > + Why doesn´t it print 1? > > Because !!$i is zero > > > > > + How is this not a bug? > > Nope, no bug. > > > > > + What is being printed here? > > !!$i which is !(!(0)) which is !(1) which is 0 > I suspect !1 returns an empty string in scalar context. > > > > + How do you do what I intended in perl? > > > > How do we know what you intend? > > -- ----- Shlomi Fish http://www.shlomifish.org/ http://shlomifishswiki.branchable.com/Self-Sufficiency/ I don’t believe in fairies. Oops! A fairy died. I don’t believe in fairies. Oops! Another fairy died. — http://www.shlomifish.org/humour.html -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
On Sat, 1 Jul 2017 17:27:02 +0200 hw wrote: > > Hi, > > can someone please explain this: > > > perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' > i: > > > Particularly: > > > + Why doesn´t it print 1? Because !!$i is zero > > + How is this not a bug? Nope, no bug. > > + What is being printed here? !!$i which is !(!(0)) which is !(1) which is 0 > > + How do you do what I intended in perl? > How do we know what you intend? -- Don't stop where the ink does. Shawn H Corey -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";'
Hi, can someone please explain this: perl -e 'my $i = 0; $i = defined($i) ? (!!$i) : 0; print "i: $i\n";' i: Particularly: + Why doesn´t it print 1? + How is this not a bug? + What is being printed here? + How do you do what I intended in perl? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
Naming multiple variables with the same name like you did ($args, %args) is a bad idea. because when you want to access the value of the hash %args ($args{FN}) you are accessing in reality what was shifted in the scalar $args and not the hash %args because perl use simbolic reference. here is a link that explain that https://perlmaven.com/symbolic-reference-in-perl *Khalil Zakaria Zemmoura* *Visiteur Médical EST* *Laboratoire NOVOMEDIS*
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
On Sun, Jan 15, 2017 at 12:45:41PM -0800, al...@myfastmail.com wrote: > Hi > > On Sun, Jan 15, 2017, at 12:23 PM, Илья Рассадин wrote: > > I think, you can use this aproach > > If I use either of those > > > sub modrec { > - my %args = %{ shift @_ }; > + my ($args) = @_; > > 30my $fn = $args{FN}; > my $ar = $args{AR}; > my $ad = $args{AD}; > my @dr = @{$args{DR}}; > > return; > } > > or > > sub modrec { > - my %args = %{ shift @_ }; > + my $args = shift @_; > > 30my $fn = $args{FN}; > my $ar = $args{AR}; > my $ad = $args{AD}; > my @dr = @{$args{DR}}; > > return; > } Naming multiple variables with the same name like you did ($args, %args) is a bad idea. because when you want to access the value of the hash %args ($args{FN}) you are accessing in reality what was shifted in the scalar $args and not the hash %args because perl use simbolic reference. here is a link that explain that https://perlmaven.com/symbolic-reference-in-perl > > the script won't even execute. Both give the same error > > perl /home/aj/test.pl > Global symbol "%args" requires explicit package name at > /home/aj/test.pl line 30. > Global symbol "%args" requires explicit package name at > /home/aj/test.pl line 31. > Global symbol "%args" requires explicit package name at > /home/aj/test.pl line 32. > Global symbol "%args" requires explicit package name at > /home/aj/test.pl line 33. > Execution of /home/aj/test.pl aborted due to compilation errors. > > Which is weird since after I make those changes I'm not even using "%args" > anymore. > > AJ > > -- > 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: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
On Sun, Jan 15, 2017, 16:19 wrote: Hi, On Sun, Jan 15, 2017, at 01:01 PM, Shawn H Corey wrote: > > Is there a different, recommended way? > > Nothing's wrong. perlcritic does not this valid method, that's all. > > TIMTOWTDI (There Is More Than One Way To Do It.) Hm, ok. As long as it's not wrong/broken in some weird way. I kept getting scolded to "check your code with perlcritic" as if that's the *right* way to do it. So when I kept getting that perlcritic-ism, I started looking around for why. LOTS of post telling you different things NOT to do, but nothing that explained in a way I could understand why what I was doing wasn't cool. I must've read & parsed that "--verbose 11" output a dozen times. Just isn't understandble :-( So, anyway, sticking with what I got until if/when I understand the point! Thanks alot. AJ In this case, what you are doing "wrong" is trusting the caller of the function. Good defensive practices will save you a ton of headache in the future. Your code expects the first (and only) argument to be a hashref. Proper checking of the arguments will save maintainers tons of time. For instance, examine these error messages: Can't use string ("FN") as a HASH ref while "strict refs" in use at sig.pl line 9. Not a HASH reference at sig.pl line 9. And now look at these error messages: wrong number of arguments at sig.pl line 13. main::better("FN", 1, "AR", 1, "AD", 1, "DR", 1) called at sig.pl line 34 eval {...} called at sig.pl line 36 argument isn't a hashref at sig.pl line 15. main::better(ARRAY(0x7fc08b0292a8)) called at sig.pl line 41 eval {...} called at sig.pl line 43 These error messages were produced by the following code. In both cases (calling with a list instead of a hashref and calling with an arrayref instead of a hashref), the first set of error messages only tell you where the code blew up, not where the programmer made an error. In the second set of error messages, you get better location information and better overall information. Now, this is obviously better for the maintainer, but it comes at the cost of more verbose code. If this is a one-off script, then it probably isn't worthwhile; however, if this is code that is meant to live for any appreciable length of time, then verbode handling is best. #!/usr/bin/perl use strict; use Carp; use warnings; sub not_so_good { my %args = %{ shift @_ }; } sub better { croak "wrong number of arguments" unless @_ == 1; my $arg = shift @_; croak "argument isn't a hashref" unless ref $arg eq ref {}; my %args = %$arg; } eval { not_so_good(FN => 1, AR => 1, AD => 1, DR => 1); 1; } or do { print "got error: $@"; }; eval { not_so_good([FN => 1, AR => 1, AD => 1, DR => 1]); 1; } or do { print "got error: $@"; }; eval { better(FN => 1, AR => 1, AD => 1, DR => 1); 1; } or do { print "got error: $@"; }; eval { better([FN => 1, AR => 1, AD => 1, DR => 1]); 1; } or do { print "got error: $@"; };
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
Hi Alan You are unpacking `@_` in a way, but perlcritic doesn't recognise doing it this way. I think you'd be better off without dereferencing the hash, and using a slice to assign your local variables. I would write your subroutine like this sub modrec { my ($args) = @_; my ($fn, $ar, $ad, $dr) = @{$args}{qw/ FN AR AD DR /}; ... } And if you must, you can dereference the array with my @dr = @$dr; but it's generally better to access the elements directly from the reference, with `$dr->[0]`, `$dr->[1]` etc. Rob On 15 January 2017 20:09:53 GMT+00:00, al...@myfastmail.com wrote: >Hi, > >I have a simple script with a subroutine that I pass scalar & array >arguments to, > > #!/usr/bin/perl > > use 5.01201; > use strict; > use warnings; > > my $this_fn = "input.txt"; > my @this_dr = qw( > /path/1 > /path/2 > ); > my $this_rn = "recname"; > my $this_ad = "1.2.3.4."; > > sub modrec { > my %args = %{ shift @_ }; > > my $fn = $args{FN}; > my $ar = $args{AR}; > my $ad = $args{AD}; > my @dr = @{$args{DR}}; > > return; > } > > modrec ( >{ > FN=>$this_fn, > DR=>\@this_dr, > AR=>$this_rn, > AD=>$this_ad, >} > ); > >The script *executes* just fine. > >But when I exec perlcritic on it > > perlcritic --verbose 11 -harsh test.pl > Always unpack @_ first at line 15, near 'sub modrec {'. > Subroutines::RequireArgUnpacking (Severity: 4) > Subroutines that use `@_' directly instead of unpacking the >arguments to > local variables first have two major problems. First, they > are >very hard > to read. If you're going to refer to your variables by > number >instead of > by name, you may as well be writing assembler code! Second, > `@_' > contains aliases to the original variables! If you modify > the >contents > of a `@_' entry, then you are modifying the variable > outside of >your > subroutine. For example: > > sub print_local_var_plus_one { > my ($var) = @_; > print ++$var; > } > sub print_var_plus_one { > print ++$_[0]; > } > > my $x = 2; > print_local_var_plus_one($x); # prints "3", $x is still 2 > print_var_plus_one($x); # prints "3", $x is now 3 ! > print $x; # prints "3" > > This is spooky action-at-a-distance and is very hard to > debug if >it's > not intentional and well-documented (like `chop' or > `chomp'). > > An exception is made for the usual delegation idiom > `$object->SUPER::something( @_ )'. Only `SUPER::' and > `NEXT::' >are > recognized (though this is configurable) and the argument > list >for the > delegate must consist only of `( @_ )'. > >What's wrong with the way I'm unpacking the arguments passed to the >subroutine, > > my %args = %{ shift @_ }; > >Is there a different, recommended way? > >AJ > >-- >To unsubscribe, e-mail: beginners-unsubscr...@perl.org >For additional commands, e-mail: beginners-h...@perl.org >http://learn.perl.org/ -- Sent from Kaiten Mail. Please excuse my brevity.
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
Hi, On Sun, Jan 15, 2017, at 01:01 PM, Shawn H Corey wrote: > > Is there a different, recommended way? > > Nothing's wrong. perlcritic does not this valid method, that's all. > > TIMTOWTDI (There Is More Than One Way To Do It.) Hm, ok. As long as it's not wrong/broken in some weird way. I kept getting scolded to "check your code with perlcritic" as if that's the *right* way to do it. So when I kept getting that perlcritic-ism, I started looking around for why. LOTS of post telling you different things NOT to do, but nothing that explained in a way I could understand why what I was doing wasn't cool. I must've read & parsed that "--verbose 11" output a dozen times. Just isn't understandble :-( So, anyway, sticking with what I got until if/when I understand the point! Thanks alot. AJ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
On Sun, 15 Jan 2017 12:09:53 -0800 al...@myfastmail.com wrote: > What's wrong with the way I'm unpacking the arguments passed to the > subroutine, > > my %args = %{ shift @_ }; > > Is there a different, recommended way? Nothing's wrong. perlcritic does not this valid method, that's all. TIMTOWTDI (There Is More Than One Way To Do It.) -- Don't stop where the ink does. Shawn H Corey -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
Hi! You forgot arrow operator $args->{'FN'}, not $args{'FN'} 15.01.17 23:45, al...@myfastmail.com пишет: Hi On Sun, Jan 15, 2017, at 12:23 PM, Илья Рассадин wrote: I think, you can use this aproach If I use either of those sub modrec { - my %args = %{ shift @_ }; + my ($args) = @_; 30 my $fn = $args{FN}; my $ar = $args{AR}; my $ad = $args{AD}; my @dr = @{$args{DR}}; return; } or sub modrec { - my %args = %{ shift @_ }; + my $args = shift @_; 30 my $fn = $args{FN}; my $ar = $args{AR}; my $ad = $args{AD}; my @dr = @{$args{DR}}; return; } the script won't even execute. Both give the same error perl /home/aj/test.pl Global symbol "%args" requires explicit package name at /home/aj/test.pl line 30. Global symbol "%args" requires explicit package name at /home/aj/test.pl line 31. Global symbol "%args" requires explicit package name at /home/aj/test.pl line 32. Global symbol "%args" requires explicit package name at /home/aj/test.pl line 33. Execution of /home/aj/test.pl aborted due to compilation errors. Which is weird since after I make those changes I'm not even using "%args" anymore. AJ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
Hi On Sun, Jan 15, 2017, at 12:23 PM, Илья Рассадин wrote: > I think, you can use this aproach If I use either of those sub modrec { - my %args = %{ shift @_ }; + my ($args) = @_; 30 my $fn = $args{FN}; my $ar = $args{AR}; my $ad = $args{AD}; my @dr = @{$args{DR}}; return; } or sub modrec { - my %args = %{ shift @_ }; + my $args = shift @_; 30 my $fn = $args{FN}; my $ar = $args{AR}; my $ad = $args{AD}; my @dr = @{$args{DR}}; return; } the script won't even execute. Both give the same error perl /home/aj/test.pl Global symbol "%args" requires explicit package name at /home/aj/test.pl line 30. Global symbol "%args" requires explicit package name at /home/aj/test.pl line 31. Global symbol "%args" requires explicit package name at /home/aj/test.pl line 32. Global symbol "%args" requires explicit package name at /home/aj/test.pl line 33. Execution of /home/aj/test.pl aborted due to compilation errors. Which is weird since after I make those changes I'm not even using "%args" anymore. AJ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
Hi! I think, you can use this aproach sub modrec { my ($args) = @_; # or my $args = shift @_; use what you like more my $fn = $args->{'FN'}; } 15.01.17 23:09, al...@myfastmail.com пишет: Hi, I have a simple script with a subroutine that I pass scalar & array arguments to, #!/usr/bin/perl use 5.01201; use strict; use warnings; my $this_fn = "input.txt"; my @this_dr = qw( /path/1 /path/2 ); my $this_rn = "recname"; my $this_ad = "1.2.3.4."; sub modrec { my %args = %{ shift @_ }; my $fn = $args{FN}; my $ar = $args{AR}; my $ad = $args{AD}; my @dr = @{$args{DR}}; return; } modrec ( { FN=>$this_fn, DR=>\@this_dr, AR=>$this_rn, AD=>$this_ad, } ); The script *executes* just fine. But when I exec perlcritic on it perlcritic --verbose 11 -harsh test.pl Always unpack @_ first at line 15, near 'sub modrec {'. Subroutines::RequireArgUnpacking (Severity: 4) Subroutines that use `@_' directly instead of unpacking the arguments to local variables first have two major problems. First, they are very hard to read. If you're going to refer to your variables by number instead of by name, you may as well be writing assembler code! Second, `@_' contains aliases to the original variables! If you modify the contents of a `@_' entry, then you are modifying the variable outside of your subroutine. For example: sub print_local_var_plus_one { my ($var) = @_; print ++$var; } sub print_var_plus_one { print ++$_[0]; } my $x = 2; print_local_var_plus_one($x); # prints "3", $x is still 2 print_var_plus_one($x); # prints "3", $x is now 3 ! print $x; # prints "3" This is spooky action-at-a-distance and is very hard to debug if it's not intentional and well-documented (like `chop' or `chomp'). An exception is made for the usual delegation idiom `$object->SUPER::something( @_ )'. Only `SUPER::' and `NEXT::' are recognized (though this is configurable) and the argument list for the delegate must consist only of `( @_ )'. What's wrong with the way I'm unpacking the arguments passed to the subroutine, my %args = %{ shift @_ }; Is there a different, recommended way? AJ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
script that passes args to subroutine works ok, after I unpack the args. But perlcritic says I'm not unpacking?
Hi, I have a simple script with a subroutine that I pass scalar & array arguments to, #!/usr/bin/perl use 5.01201; use strict; use warnings; my $this_fn = "input.txt"; my @this_dr = qw( /path/1 /path/2 ); my $this_rn = "recname"; my $this_ad = "1.2.3.4."; sub modrec { my %args = %{ shift @_ }; my $fn = $args{FN}; my $ar = $args{AR}; my $ad = $args{AD}; my @dr = @{$args{DR}}; return; } modrec ( { FN=>$this_fn, DR=>\@this_dr, AR=>$this_rn, AD=>$this_ad, } ); The script *executes* just fine. But when I exec perlcritic on it perlcritic --verbose 11 -harsh test.pl Always unpack @_ first at line 15, near 'sub modrec {'. Subroutines::RequireArgUnpacking (Severity: 4) Subroutines that use `@_' directly instead of unpacking the arguments to local variables first have two major problems. First, they are very hard to read. If you're going to refer to your variables by number instead of by name, you may as well be writing assembler code! Second, `@_' contains aliases to the original variables! If you modify the contents of a `@_' entry, then you are modifying the variable outside of your subroutine. For example: sub print_local_var_plus_one { my ($var) = @_; print ++$var; } sub print_var_plus_one { print ++$_[0]; } my $x = 2; print_local_var_plus_one($x); # prints "3", $x is still 2 print_var_plus_one($x); # prints "3", $x is now 3 ! print $x; # prints "3" This is spooky action-at-a-distance and is very hard to debug if it's not intentional and well-documented (like `chop' or `chomp'). An exception is made for the usual delegation idiom `$object->SUPER::something( @_ )'. Only `SUPER::' and `NEXT::' are recognized (though this is configurable) and the argument list for the delegate must consist only of `( @_ )'. What's wrong with the way I'm unpacking the arguments passed to the subroutine, my %args = %{ shift @_ }; Is there a different, recommended way? AJ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
What is the Perl equivalent of "net user username \domain" if I am on Linux or Mac?
Hi; What is the Perl equivalent of "net user username \domain" if I am on Linux or Mac? None of our Linux or Mac machines are a member of the specific domain in question. Do have to obtain the name of the AD/LDAP server and obtain some kind of credentials for me to inquire about a specific user? I already have a Perl script written that works on Cygwin that goes through the output of p4 users one by one, checking them against the output of "net user user_name /domain" to see if they are still employees. If they aren't, then I can remove their Perforce account. So, I assume that I will need to do something with LDAP, and need IT to give me meaningful information to interact with the LDAP server and permission to interact with it. I assume also that if they do not share this information and/or are unwilling to provide access to interact with LDAP via a script, that I have no choice but to use Cygwin and "net user user_name /domain" to verify that the user of the Perforce account is still an employee or not. Please advise. Thanks, Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
my makefile. Doesn’t work the way I intend it to
Hello Group, I have the following in my makefile. Doesn’t work the way I intend it to. How do I do conditional test with a regular expression ? ifeq (${HOST_TYPE},x86_64)-- à works ifeq (${LATTICE_VERSION},d3.*) --à doesn’t work LATTICE_EXE_PATH = ${ISPFPGA}/bin/lin64 else LATTICE_EXE_PATH = ${ISPFPGA}/bin/lin endif else LATTICE_EXE_PATH = ${ISPFPGA}/bin/lin endif with Regards Uday V G -- * Don't ask them WHY they hurt you, because all they'll tell you is lies and excuses. Just know they were wrong, and try to move on. **
Re: How do I fork a process and return results to the user?
Hi G, please reply to all recipients. On Sun, 30 Aug 2015 21:47:47 + G M wrote: > Hi, > Can anyone help me with this? > I have two scripts, the first one calls the exec command which then invokes > the second script. The second script then creates a fork process. The child > process in the fork does a webservice query which may take a few minutes to > return results. What I want to do is forward the user to a "Searching for > results" page which polls periodically for results. Eventually it will > display the search results. How can I do this? Once the background fork > process is running I have no idea how to get forward the user to a new page > and display the results on that page. Any help with this would be great as > I'm pretty much stumped. > You may wish to look at: 1. AJAX / Redirects - see https://en.wikipedia.org/wiki/Ajax_%28programming%29 . 2. Async / event-driven programming - http://perl-begin.org/uses/multitasking/ . 3. Sockets / networking (or something filesystem based with locks). 4. Your web-service configuration for mapping a service URL. Regards, Shlomi Fish Note: perl-begin.org is a domain I maintain. -- - Shlomi Fish http://www.shlomifish.org/ Escape from GNU Autohell - http://www.shlomifish.org/open-source/anti/autohell/ What's the point of claiming your code is illegal? I might anger a few, but I just wanna sue — http://www.shlomifish.org/humour/bits/Can-I-SCO-Now/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
How do I fork a process and return results to the user?
Hi, Can anyone help me with this? I have two scripts, the first one calls the exec command which then invokes the second script. The second script then creates a fork process. The child process in the fork does a webservice query which may take a few minutes to return results. What I want to do is forward the user to a "Searching for results" page which polls periodically for results. Eventually it will display the search results. How can I do this? Once the background fork process is running I have no idea how to get forward the user to a new page and display the results on that page. Any help with this would be great as I'm pretty much stumped. Thank you, G :)
Re: Can I join this mailing list please?
HI Zackary, Yes you can. Use the "How do I subscribe?" section in the below link. http://learn.perl.org/faq/beginners.html#subscribe Thank You, Ram Murthy On Thu, May 14, 2015 at 5:21 PM, Zackary M wrote: > Thanks! > > Zac >
Re: Can I join this mailing list please?
Hi Zac, On Thu, 14 May 2015 07:51:50 -0400 Zackary M wrote: > Thanks! > > Zac I don't see why you cannot. See http://learn.perl.org/faq/beginners.html#subscribe for subscription instructions. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ http://youtu.be/KxGRhd_iWuE - Never Give Up!! If a tree falls down in the middle of the forest, and there’s no one there to hear it… what colour is the tree? — Monkey Island 2: LeChuck’s Revenge Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Can I join this mailing list please?
Thanks! Zac
Re: Eclipse - How do I get back to the first splash screen
> On Mar 13, 2015, at 2:07 PM, Sherman Willden > wrote: > > I downloaded Eclipse and I was looking at the screens and in general just > messing with Eclipse. Now I can't find the first splash screen with the > tutorials, samples, and such. Also is there a help button on Eclipse? It has been awhile since I first downloaded and installed Eclipse, but in the version (Indigo) I have on my system, the Help -> Welcome menu item gets you to that initial splash screen with Overview, Samples, Tutorials, and What’s New. As far as a Help button, there is a Help menu. Does that have what you are looking for? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Eclipse - How do I get back to the first splash screen
I downloaded Eclipse and I was looking at the screens and in general just messing with Eclipse. Now I can't find the first splash screen with the tutorials, samples, and such. Also is there a help button on Eclipse? Thank you; Sherman
Re: An issue of Scope that I do not understand
Charles DeRykus writes: > You could also simplify the closure since @tasks is in the closure's > lexical scope, eg, > > my $report_static = sub { print $tasks[$iter++]; ... }; > > foreach $task (@tasks) { > if (...) > $report_statics->(); > else > $report_dynamic->(); > ... > } > > But with everything in lexical scope, you could just pass any needed > arg's directly and > eliminate the closure altogether. Many thanks. I actually did simply pass $task to each of those subroutines then put my $task = shift; inside the sub to copy the variable and they now work like they should again or at least they began to work after I installed the ; I forgot after the } on one of the subs. The errors one gets when forgetting that semicolon are almost as fun as the ones one gets when a { or } is missing or there is an extra one from moving lines around. They tend to point to everything but the real cause. The saving factor is that they usually point to problems outside the scope of the subroutine and flag code that was known to be good. Move the subroutine around and you poison everything after it I think the perl debugger is really clever in that it usually guides you right to the problem and when it doesn't, one can still get an idea roughly of what is wrong by the general tone of the squawks. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
> ... > > I'm not sure why you don't just pass $task as an argument to the > report_xxx subs...? > > A closure (perldoc -q closure) would be the long way around unless > I've missed something: > > my $task; > my $iter; > my $report_static = sub { my $ref = shift; > print $ref->[$iter++]; > > }; > > my $report_dynamic = sub( my $ref = shift; >print $ref->[$iter++]; >... > > #MAIN_CODE START > > foreach $task (@tasks) { > if ( ) >$report_static->(\@tasks); >... > else > $report_dynamic->(\@tasks); >... > } > } > > You could also simplify the closure since @tasks is in the closure's lexical scope, eg, my $report_static = sub { print $tasks[$iter++]; ... }; foreach $task (@tasks) { if (...) $report_statics->(); else $report_dynamic->(); ... } But with everything in lexical scope, you could just pass any needed arg's directly and eliminate the closure altogether. -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
Hi Martin, thanks for your kind words. On Sat, 28 Feb 2015 09:01:26 -0600 "Martin G. McCormick" wrote: > Shlomi Fish writes: > http://perl-begin.org/tutorials/bad-elements/#declaring_all_vars_at_top > > > > (Note: perl-begin.org is a domain I originated and maintain). > > Shlomi Fish, Uri and Brock, > > I certainly wish I had known about a resource like this > earlier in my relatively short perl career. Thanks for the compliment. Note that that page is heavily inspired by the book https://en.wikipedia.org/wiki/Perl_Best_Practices by Damian Conway. So you should extend your thanks to him as well. > > One can find limitless samples of good and bad perl code > on the internet and from textbooks but programming languages > really shine when one knows why or at least somewhat knows why > the coding is done in a certain way which usually boils down to > making it easier to comprehend by someone else or making it > easier or even possible for the compiler or interpreter to > process. > > I knew I could probably cobble together something that > fixed the problem I was asking about but the way the code I > wrote failed told me that I didn't understand all I thought I > knew. > > I actually thought pre-declaring the variables was a > good thing since I had been doing that in C and various > assemblers for 35 years if you count all the way back to when I > got in to computing by accident after going to college to do > something totally different. Ah, I'm not sure pre-declaration is still recommended in C++, as well as C99 and later versions where variables can be declared and initialised in the middle of a block. > > I expect the large code I have written will now work > after applying the following quote from your site: > > > However, this is bad form in Perl, and the preferable way is to declare > > all the variables when they are first used, and at the innermost scope > > where they should retain their value. This will allow to keep track of > > them better. > > Again, thanks for creating this great resource. I hope I can > stop reading it long enough to fix the problem at hand. You're welcome. If you'd like to help me a little as gratitude, please see these pages about it: * http://perl-begin.org/contribute/ * http://www.shlomifish.org/meta/how-to-help/ * http://www.shlomifish.org/meta/donate/ (*NOTE*: www.shlomifish.org is my personal web site.) > > My last day of work before retirement is Monday, March 2 > but I will just be starting something new at the age of 63 > rather than going away. :-). Also see http://www.shlomifish.org/humour/fortunes/show.cgi?id=quora-learning-to-drum-at-65 . Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Best Introductory Programming Language - http://shlom.in/intro-lang To have bugs is human; to fix them — divine. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
Shlomi Fish writes: http://perl-begin.org/tutorials/bad-elements/#declaring_all_vars_at_top > > (Note: perl-begin.org is a domain I originated and maintain). Shlomi Fish, Uri and Brock, I certainly wish I had known about a resource like this earlier in my relatively short perl career. One can find limitless samples of good and bad perl code on the internet and from textbooks but programming languages really shine when one knows why or at least somewhat knows why the coding is done in a certain way which usually boils down to making it easier to comprehend by someone else or making it easier or even possible for the compiler or interpreter to process. I knew I could probably cobble together something that fixed the problem I was asking about but the way the code I wrote failed told me that I didn't understand all I thought I knew. I actually thought pre-declaring the variables was a good thing since I had been doing that in C and various assemblers for 35 years if you count all the way back to when I got in to computing by accident after going to college to do something totally different. I expect the large code I have written will now work after applying the following quote from your site: > However, this is bad form in Perl, and the preferable way is to declare > all the variables when they are first used, and at the innermost scope > where they should retain their value. This will allow to keep track of > them better. Again, thanks for creating this great resource. I hope I can stop reading it long enough to fix the problem at hand. My last day of work before retirement is Monday, March 2 but I will just be starting something new at the age of 63 rather than going away. Martin McCormick -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
Hi Martin, here are some comments on your code in addition to what Uri said. On Fri, 27 Feb 2015 22:24:52 -0600 "Martin G. McCormick" wrote: > Brock Wilcox writes: > > I'm afraid a bit more context is needed to identify the problem. Could you > > post your entire bit of code into a gist or pastebin or something for us > > to > > see? > > I'll do better than that. This is a script which is > stripped of everything but the problem code. It is 20 lines long > and here it is. > > #!/usr/bin/perl -w > use strict; "use strict;" is goot, but the "-w" flag should be replaced by "use warnings;": http://perl-begin.org/tutorials/bad-elements/#the-dash-w-flag (Note: perl-begin.org is a domain I originated and maintain). > > #Declare main variables. > > #main locals > my @tasks; > my $task; > my $report_static; > $report_static = sub { > print "$task\n"; > }; > It's a good idea to avoid predeclarations: http://perl-begin.org/tutorials/bad-elements/#declaring_all_vars_at_top Usually "my $var" should be immediately followed by an assignment using "=". > #MAIN_CODE START > $tasks[0] = "red"; > $tasks[1] = "blue"; > $tasks[2] = "green"; You can either do «my @tasks = ("red", "blue", "green");» (or «my @tasks = qw(red blue green);» or use push, see: http://perl-begin.org/tutorials/bad-elements/#appending_using_arr_increment Don't use indexes in succession. > foreach $task (@tasks) { > &$report_static; The problem with «&$sub_ref;» (without parentheses) is that it also passes @_ to $sub_ref. Either write: &$sub_ref(); Or better yet: $sub_ref->(); Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ UNIX Fortune Cookies - http://www.shlomifish.org/humour/fortunes/ If you have the same ideas as everybody else, but have them one week earlier than everyone else — then you will be hailed as a visionary. But if you have them five years earlier, you will be named a lunatic. ( Barry Jones ) Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
On Fri, Feb 27, 2015 at 8:24 PM, Martin G. McCormick wrote: > Brock Wilcox writes: >> I'm afraid a bit more context is needed to identify the problem. Could you >> post your entire bit of code into a gist or pastebin or something for us >> to >> see? > > I'll do better than that. This is a script which is > stripped of everything but the problem code. It is 20 lines long > and here it is. > > #!/usr/bin/perl -w > use strict; > > #Declare main variables. > > #main locals > my @tasks; > my $task; > my $report_static; > $report_static = sub { > print "$task\n"; > }; > > #MAIN_CODE START > $tasks[0] = "red"; > $tasks[1] = "blue"; > $tasks[2] = "green"; > foreach $task (@tasks) { > &$report_static; > } > I'm not sure why you don't just pass $task as an argument to the report_xxx subs...? A closure (perldoc -q closure) would be the long way around unless I've missed something: my $task; my $iter; my $report_static = sub { my $ref = shift; print $ref->[$iter++]; }; my $report_dynamic = sub( my $ref = shift; print $ref->[$iter++]; ... #MAIN_CODE START foreach $task (@tasks) { if ( ) $report_static->(\@tasks); ... else $report_dynamic->(\@tasks); ... } } -- Charles DeRykus -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
On 02/27/2015 11:24 PM, Martin G. McCormick wrote: Brock Wilcox writes: I'm afraid a bit more context is needed to identify the problem. Could you post your entire bit of code into a gist or pastebin or something for us to see? I'll do better than that. This is a script which is stripped of everything but the problem code. It is 20 lines long and here it is. #!/usr/bin/perl -w use strict; #Declare main variables. #main locals my @tasks; my $task; my $report_static; $report_static = sub { print "$task\n"; }; that $task is bound to the outer $task #MAIN_CODE START $tasks[0] = "red"; $tasks[1] = "blue"; $tasks[2] = "green"; that can be done with: my @tasks = qw( red blue green ) ; foreach $task (@tasks) { that $task is localized to the loop (with local()). see this in perlsyn: The "foreach" loop iterates over a normal list value and sets the variable VAR to be each element of the list in turn. If the variable is preceded with the keyword "my", then it is lexically scoped, and is therefore visible only within the loop. Otherwise, the variable is implicitly local to the loop and regains its former value upon exiting the loop. If the variable was previously declared with "my", it uses that variable instead of the global one, but it's still localized to the loop. This implicit localization occurs only in a "foreach" loop. what are you trying to do here? closures are very useful but rarely do beginners need them and there is no need in that example and likely in your real problem as well. i smell an XY problem and you are likely to just need better data structures or passing data by reference. closures are not commonly used in basic code - they have a purpose but a rule i say is you can use an advanced feature until you know when you are not supposed to use it. thanx, uri -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
Brock Wilcox writes: > I'm afraid a bit more context is needed to identify the problem. Could you > post your entire bit of code into a gist or pastebin or something for us > to > see? I'll do better than that. This is a script which is stripped of everything but the problem code. It is 20 lines long and here it is. #!/usr/bin/perl -w use strict; #Declare main variables. #main locals my @tasks; my $task; my $report_static; $report_static = sub { print "$task\n"; }; #MAIN_CODE START $tasks[0] = "red"; $tasks[1] = "blue"; $tasks[2] = "green"; foreach $task (@tasks) { &$report_static; } -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: An issue of Scope that I do not understand
I'm afraid a bit more context is needed to identify the problem. Could you post your entire bit of code into a gist or pastebin or something for us to see? On Feb 27, 2015 9:52 PM, "Martin G. McCormick" < mar...@server1.shellworld.net> wrote: > I put together an anonymous subroutine which partly > works. There is an array called @tasks which is defined as a > local variable in the main routine and when I call the anonymous > subroutine, one can still read all the elements in @tasks. > > There is also a single scaler called $task, also created > in main and a foreach loop > > foreach $task (@tasks) {#may be a lease > @results = whatisit($task); > if ( $results[0] eq "IP" ) {#This could be bootP or dynamic. > $numerical_lookup = ipaddr_to_num($task); > @dynamics = netfind($numerical_lookup); > > #dynamics[1] has a value when this is a dynamic lease. > if ( $dynamics[1] ) { #It's dynamic. > &$report_dynamic; > } #It's dynamic. > else {#static > &$report_static; > }#static > }#This could be bootP or dynamic. > > All the code in my sample that you see does work as it should > and gets you to either the report_dynamic orreport_static > anonymous subs. Here is the beginning of the report_static > subroutine. First I declare a local variable in main to use for > the name of the anonymous subroutine. > > my $report_static; > > That is fine. The trouble starts immediately when the subroutine > does. > > $report_static = sub {#What is at this static address? > @hostnames = revdns($task); > > That's where things explode. If I trace each step in that > subroutine, I can still read @tasks but $task has disappeared > the instant I am in the report_static subroutine. > > This is a pretty large application, about 1230 lines and > the logic did work when it all was part of main. > > I would at least think I understood what was happening > if both the @tasks array and the $task scaler became undefined > in report_static but only the scaler goes "poof!" What I was > hoping for was for the loop in the main portion to select which > element in @tasks was used and the anonymous subroutine would do > what it needed to do just as it had done when it was all in > main. > > I am familiar with declaring my $variable; or our > $variable; if one shares variables between subroutines but I > just assumed that in an anonymous subroutine, one was still > working with the same scope as the variables in the routine that > called the subroutine. > > Thanks for any constructive suggestions. > > Martin McCormick > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
An issue of Scope that I do not understand
I put together an anonymous subroutine which partly works. There is an array called @tasks which is defined as a local variable in the main routine and when I call the anonymous subroutine, one can still read all the elements in @tasks. There is also a single scaler called $task, also created in main and a foreach loop foreach $task (@tasks) {#may be a lease @results = whatisit($task); if ( $results[0] eq "IP" ) {#This could be bootP or dynamic. $numerical_lookup = ipaddr_to_num($task); @dynamics = netfind($numerical_lookup); #dynamics[1] has a value when this is a dynamic lease. if ( $dynamics[1] ) { #It's dynamic. &$report_dynamic; } #It's dynamic. else {#static &$report_static; }#static }#This could be bootP or dynamic. All the code in my sample that you see does work as it should and gets you to either the report_dynamic orreport_static anonymous subs. Here is the beginning of the report_static subroutine. First I declare a local variable in main to use for the name of the anonymous subroutine. my $report_static; That is fine. The trouble starts immediately when the subroutine does. $report_static = sub {#What is at this static address? @hostnames = revdns($task); That's where things explode. If I trace each step in that subroutine, I can still read @tasks but $task has disappeared the instant I am in the report_static subroutine. This is a pretty large application, about 1230 lines and the logic did work when it all was part of main. I would at least think I understood what was happening if both the @tasks array and the $task scaler became undefined in report_static but only the scaler goes "poof!" What I was hoping for was for the loop in the main portion to select which element in @tasks was used and the anonymous subroutine would do what it needed to do just as it had done when it was all in main. I am familiar with declaring my $variable; or our $variable; if one shares variables between subroutines but I just assumed that in an anonymous subroutine, one was still working with the same scope as the variables in the routine that called the subroutine. Thanks for any constructive suggestions. Martin McCormick -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Should I add ExtUtils::MakeMaker as prerequisite to Makefile?
On Fri, 27 Feb 2015 23:41:22 +0100 Alex Becker wrote: > So my idea was to specify EUMM v6.46 as minimum in PREREQ_PM. This > way, I would not have to do all this 'if the EUMM version is greater > than X then add Y to Makefile.PL' stuff. > > So, would it work? Does it make sense? I don't think so; I think older EU::MM versions would choke on the options they don't support before they'd get as far as checking PREREQ_PM and seeing that you've asked for a newer EU::MM version. You could always try it and see, but I don't think it'd work for you. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Should I add ExtUtils::MakeMaker as prerequisite to Makefile?
Hi! When writing a Makefile.PL for a module (no, I don't want to read about other ways to do it now), does it make sense to add ExtUtils::MakeMaker (EUMM) to the PREREQ_PM module prerequisites list? I'm asking because I saw some Makefile.PL where the installed version of EUMM was checked and depending on the version, some additional information was added. For example, when using META_MERGE, a user has to have EUMM installed in version 6.46 at minimum. So my idea was to specify EUMM v6.46 as minimum in PREREQ_PM. This way, I would not have to do all this 'if the EUMM version is greater than X then add Y to Makefile.PL' stuff. So, would it work? Does it make sense? Thanks in advance for the answers and best regards, Alex
Re: Just gotten back into Perl, wondering how I could better write my first app.
Hi Mike, On Sat, 10 May 2014 04:31:31 -0500 Mike Dunaway wrote: > Hi Shlomi, > > Thanks for the feedback. > > My intention with my $files, according to the documentation for > Archive::Tar is that you're supposed to be able to provide a list of > files. It is my intention for the user to provide a single file or a > directory, but it doesn't seem to be working properly. > > I've tried running it like so: > > $ ./eztar -c git.tar.gz * > > And only one file in the working directory seems to be getting added to > the tarball so I think I may be doing something incorrect. Likewise with > listing contents of a tarball, only the top most files inside the > tarball is getting listed when using the -l switch so I think I might be > doing something wrong there, as well. This is expected because on the UNIX shell the asterisk ("*") gets wildcard-expanded into a list of files in the current directory and the are added to @ARGV one by one. See https://en.wikipedia.org/wiki/Glob_%28programming%29 . What you probably want is: my ($archive, @list_of_files) = @ARGV; See: http://altreus.blogspot.com.au/2011/08/lists-and-things-made-of-lists.html One other note is that doing something like "tar -cavf myarc.tar.gz *" is not advisable because: 1. If myarc.tar.gz already exists in the directory it may be clobbered. and - 2. It is to mistake with "tar -cavf *" which will clobber the first file it finds (and it happened to a co-student of mine at the Technion who had to redo most of his work). I try to always do "tar -cavf myarc.tar.gz mydir/". If you're looking for a packaging interface, see patool: https://freecode.com/projects/patool Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ List of Portability Libraries - http://shlom.in/port-libs Live as if you were to die tomorrow. Learn as if you were to live forever. — http://en.wikiquote.org/wiki/Mohandas_Gandhi (Disputed) Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Just gotten back into Perl, wondering how I could better write my first app.
Hi Shlomi, Thanks for the feedback. My intention with my $files, according to the documentation for Archive::Tar is that you're supposed to be able to provide a list of files. It is my intention for the user to provide a single file or a directory, but it doesn't seem to be working properly. I've tried running it like so: $ ./eztar -c git.tar.gz * And only one file in the working directory seems to be getting added to the tarball so I think I may be doing something incorrect. Likewise with listing contents of a tarball, only the top most files inside the tarball is getting listed when using the -l switch so I think I might be doing something wrong there, as well. On 05/10/2014 04:25 AM, Shlomi Fish wrote: Hi Mike, you have not replied to my earlier E-mail about trying to explain the code in MetaCPAN::API. Please do so, or else you'll follow this - http://www.shlomifish.org/humour/fortunes/show.cgi?id=God_gave_us_two_eyes . Also - please reply to all recipients - select the right option in GMail.com or whatever your client is. On Sat, 10 May 2014 04:01:06 -0500 Mike Dunaway wrote: So I've just gotten back into Perl and I've written a tarring utility for my first application. It seems to work okay, but I'm wondering how it could better be written. Any ideas? #!/usr/bin/perl -w Do not use the -w flag - use "use warnings;" instead: use strict; use Archive::Tar; use Getopt::Std; Do not use Getopt::Std - use Getopt::Long instead. use feature qw(say); my %opt; getopts('hcel', \%opt); help() if $opt{h}; list() if $opt{l}; extract() if $opt{e}; compress() if $opt{c}; These options should be mutually exclusive - maybe do: if ($opt{h}) { help(); } elsif ($opt{l}) { list(); } … sub help { say "Easily create and extract tarballs"; say " -h display this menu"; say " -c compress file/directory"; say " | eztar -c "; say " -e extract tarball"; say " | eztar -e "; say " -l list contents of tarball"; say " | eztar -l "; This should be a here document - https://en.wikipedia.org/wiki/Here_document . } sub list { if (defined $ARGV[0]) { my $tar = Archive::Tar->new(); for($tar->list_archive($ARGV[0])) { Do not use position $ARGV[0] arguments, instead extract out of @ARGV: http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments (Note that perl-begin.org is my domain). Your indentation is wrong, as well. Finally, do not use $_ for iteration - use a lexical variable instead: http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore say $_; exit 0; } } else { die 'No file provided.' } } sub extract { if (defined $ARGV[0]) { my $tar = Archive::Tar->new(); $tar->read($ARGV[0]); Indentation is off again. $tar->extract(); } else { die 'No file provided.'; } } sub compress { my $file_name = $ARGV[0] or die 'No file name specified.'; if ($file_name !~ /.*\.tar\.gz$/) { die 'File name must end with \'.tar.gz\''; } This regular expression match can be simplified into: if ($file_name !~ /\.tar\.gz$/) (without the .* which is unnecessary) And please consider using \z for end-of-string instead of $. my $files = $ARGV[1] or die 'No files specified.'; $files is in plural, but it is a scalar and a single string. What is your intention? Also see: http://perl-begin.org/tutorials/bad-elements/#calling-variables-file my $tar = Archive::Tar->new(); $tar->write($file_name); $tar->read($file_name); $tar->add_files($files); $tar->write($file_name, COMPRESS_GZIP); So far so good. Regards, Shlomi Fish -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Just gotten back into Perl, wondering how I could better write my first app.
Hey Shaji, Thanks for the tip. I'll look into that. On 05/10/2014 04:23 AM, Shaji Kalidasan wrote: Dear Mike, Instead of '-w' you can use 'use warnings' as you are using Perl version 5.10 and above. One more thing for your help subroutine you can use here document instead. Here is the code snippet sub help { print << "MENU"; Easily create and extract tarballs -h display this menu -c compress file/directory"; | eztar -c to compress> -e extract tarball | eztar -e ; -l list contents of tarball"; | eztar -l "; MENU } I am not going much into the technical aspects. Hope someone will throw more light into the technical details and the best practices. Shaji On Sat, May 10, 2014 at 2:31 PM, Mike Dunaway <mailto:ekimduna...@gmail.com>> wrote: So I've just gotten back into Perl and I've written a tarring utility for my first application. It seems to work okay, but I'm wondering how it could better be written. Any ideas? #!/usr/bin/perl -w use strict; use Archive::Tar; use Getopt::Std; use feature qw(say); my %opt; getopts('hcel', \%opt); help() if $opt{h}; list() if $opt{l}; extract() if $opt{e}; compress() if $opt{c}; sub help { say "Easily create and extract tarballs"; say " -h display this menu"; say " -c compress file/directory"; say " | eztar -c "; say " -e extract tarball"; say " | eztar -e "; say " -l list contents of tarball"; say " | eztar -l "; } sub list { if (defined $ARGV[0]) { my $tar = Archive::Tar->new(); for($tar->list_archive($ARGV[0])) { say $_; exit 0; } } else { die 'No file provided.' } } sub extract { if (defined $ARGV[0]) { my $tar = Archive::Tar->new(); $tar->read($ARGV[0]); $tar->extract(); } else { die 'No file provided.'; } } sub compress { my $file_name = $ARGV[0] or die 'No file name specified.'; if ($file_name !~ /.*\.tar\.gz$/) { die 'File name must end with \'.tar.gz\''; } my $files = $ARGV[1] or die 'No files specified.'; my $tar = Archive::Tar->new(); $tar->write($file_name); $tar->read($file_name); $tar->add_files($files); $tar->write($file_name, COMPRESS_GZIP); } -- best, Shaji -- Your talent is God's gift to you. What you do with it is your gift back to God. --
Re: Just gotten back into Perl, wondering how I could better write my first app.
Hi Mike, you have not replied to my earlier E-mail about trying to explain the code in MetaCPAN::API. Please do so, or else you'll follow this - http://www.shlomifish.org/humour/fortunes/show.cgi?id=God_gave_us_two_eyes . Also - please reply to all recipients - select the right option in GMail.com or whatever your client is. On Sat, 10 May 2014 04:01:06 -0500 Mike Dunaway wrote: > So I've just gotten back into Perl and I've written a tarring utility > for my first application. It seems to work okay, but I'm wondering how > it could better be written. Any ideas? > > > #!/usr/bin/perl -w Do not use the -w flag - use "use warnings;" instead: > use strict; > use Archive::Tar; > use Getopt::Std; Do not use Getopt::Std - use Getopt::Long instead. > use feature qw(say); > > my %opt; > > getopts('hcel', \%opt); > > help() if $opt{h}; > list() if $opt{l}; > extract() if $opt{e}; > compress() if $opt{c}; These options should be mutually exclusive - maybe do: if ($opt{h}) { help(); } elsif ($opt{l}) { list(); } … > > sub help { > say "Easily create and extract tarballs"; > say " -h display this menu"; > say " -c compress file/directory"; > say " | eztar -c > "; > say " -e extract tarball"; > say " | eztar -e "; > say " -l list contents of tarball"; > say " | eztar -l "; This should be a here document - https://en.wikipedia.org/wiki/Here_document . > } > > sub list { > if (defined $ARGV[0]) { > my $tar = Archive::Tar->new(); > for($tar->list_archive($ARGV[0])) { Do not use position $ARGV[0] arguments, instead extract out of @ARGV: http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments (Note that perl-begin.org is my domain). Your indentation is wrong, as well. Finally, do not use $_ for iteration - use a lexical variable instead: http://perl-begin.org/tutorials/bad-elements/#overuse_dollar_underscore > say $_; > exit 0; > } > } else { > die 'No file provided.' > } > } > > sub extract { > if (defined $ARGV[0]) { > my $tar = Archive::Tar->new(); > $tar->read($ARGV[0]); Indentation is off again. > $tar->extract(); > } else { > die 'No file provided.'; > } > } > > sub compress { > my $file_name = $ARGV[0] or die 'No file name specified.'; > if ($file_name !~ /.*\.tar\.gz$/) { > die 'File name must end with \'.tar.gz\''; > } This regular expression match can be simplified into: if ($file_name !~ /\.tar\.gz$/) (without the .* which is unnecessary) And please consider using \z for end-of-string instead of $. > my $files = $ARGV[1] or die 'No files specified.'; $files is in plural, but it is a scalar and a single string. What is your intention? Also see: http://perl-begin.org/tutorials/bad-elements/#calling-variables-file > my $tar = Archive::Tar->new(); > $tar->write($file_name); > $tar->read($file_name); > $tar->add_files($files); > $tar->write($file_name, COMPRESS_GZIP); So far so good. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Free (Creative Commons) Music Downloads, Reviews and more - http://jamendo.com/ I may be a geek, but I’m a true Klingon geek‐warrior! And a true Klingon geek warrior ALWAYS bottom‐posts. Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Just gotten back into Perl, wondering how I could better write my first app.
Dear Mike, Instead of '-w' you can use 'use warnings' as you are using Perl version 5.10 and above. One more thing for your help subroutine you can use here document instead. Here is the code snippet sub help { print << "MENU"; Easily create and extract tarballs -h display this menu -c compress file/directory"; | eztar -c -e extract tarball | eztar -e ; -l list contents of tarball"; | eztar -l "; MENU } I am not going much into the technical aspects. Hope someone will throw more light into the technical details and the best practices. Shaji On Sat, May 10, 2014 at 2:31 PM, Mike Dunaway wrote: > So I've just gotten back into Perl and I've written a tarring utility for > my first application. It seems to work okay, but I'm wondering how it could > better be written. Any ideas? > > > #!/usr/bin/perl -w > use strict; > use Archive::Tar; > use Getopt::Std; > use feature qw(say); > > my %opt; > > getopts('hcel', \%opt); > > help() if $opt{h}; > list() if $opt{l}; > extract() if $opt{e}; > compress() if $opt{c}; > > sub help { > say "Easily create and extract tarballs"; > say " -h display this menu"; > say " -c compress file/directory"; > say " | eztar -c wish to compress>"; > say " -e extract tarball"; > say " | eztar -e "; > say " -l list contents of tarball"; > say " | eztar -l "; > } > > sub list { > if (defined $ARGV[0]) { > my $tar = Archive::Tar->new(); > for($tar->list_archive($ARGV[0])) { > say $_; > exit 0; > } > } else { > die 'No file provided.' > } > } > > sub extract { > if (defined $ARGV[0]) { > my $tar = Archive::Tar->new(); > $tar->read($ARGV[0]); > $tar->extract(); > } else { > die 'No file provided.'; > } > } > > sub compress { > my $file_name = $ARGV[0] or die 'No file name specified.'; > if ($file_name !~ /.*\.tar\.gz$/) { > die 'File name must end with \'.tar.gz\''; > } > my $files = $ARGV[1] or die 'No files specified.'; > my $tar = Archive::Tar->new(); > $tar->write($file_name); > $tar->read($file_name); > $tar->add_files($files); > $tar->write($file_name, COMPRESS_GZIP); > } > > -- best, Shaji -- Your talent is God's gift to you. What you do with it is your gift back to God. --
Just gotten back into Perl, wondering how I could better write my first app.
So I've just gotten back into Perl and I've written a tarring utility for my first application. It seems to work okay, but I'm wondering how it could better be written. Any ideas? #!/usr/bin/perl -w use strict; use Archive::Tar; use Getopt::Std; use feature qw(say); my %opt; getopts('hcel', \%opt); help() if $opt{h}; list() if $opt{l}; extract() if $opt{e}; compress() if $opt{c}; sub help { say "Easily create and extract tarballs"; say " -h display this menu"; say " -c compress file/directory"; say " | eztar -c "; say " -e extract tarball"; say " | eztar -e "; say " -l list contents of tarball"; say " | eztar -l "; } sub list { if (defined $ARGV[0]) { my $tar = Archive::Tar->new(); for($tar->list_archive($ARGV[0])) { say $_; exit 0; } } else { die 'No file provided.' } } sub extract { if (defined $ARGV[0]) { my $tar = Archive::Tar->new(); $tar->read($ARGV[0]); $tar->extract(); } else { die 'No file provided.'; } } sub compress { my $file_name = $ARGV[0] or die 'No file name specified.'; if ($file_name !~ /.*\.tar\.gz$/) { die 'File name must end with \'.tar.gz\''; } my $files = $ARGV[1] or die 'No files specified.'; my $tar = Archive::Tar->new(); $tar->write($file_name); $tar->read($file_name); $tar->add_files($files); $tar->write($file_name, COMPRESS_GZIP); }
Re: How do I pass arrays into a subroutine
Hello, On 09/07/2013 02:15 PM, Dr.Ruud wrote: On 07/09/2013 13:43, Karol Bujaček wrote: print Dumper(@_);# just look how the @_ looks like Consider: print Dumper( \@_ ); I chose Data::Dumper::Simple <http://search.cpan.org/~ovid/Data-Dumper-Simple-0.11/lib/Data/Dumper/Simple.pm> which has such sentence in the documentation: ‘Note that there's no need to even take a reference to the variables.’ Therefore I expected that filters used in the D::D::S uses references somehow automatically. Is this guess wrong? my($animals, $digits) = @_; my @animals = @$animals; # dereference my @digits = @$digits; # dereference The comment is inaccurate. Why would you want to copy the arrays? Because I don't want to change an array by my subroutine, as Shawn H Corey answered already. Well, this may or may not be eventual's intention, apt remark. Best regards, Karol -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How do I pass arrays into a subroutine
On Sat, 07 Sep 2013 14:15:39 +0200 "Dr.Ruud" wrote: > On 07/09/2013 13:43, Karol Bujaček wrote: > > >print Dumper(@_);# just look how the @_ looks like > > Consider: print Dumper( \@_ ); > > > >my($animals, $digits) = @_; > > > >my @animals = @$animals; # dereference > >my @digits = @$digits; # dereference > > The comment is inaccurate. > > Why would you want to copy the arrays? So you could can their contents without the contents of the arrays in the caller being changed. > > > >print Dumper(@animals, @digits); # just look ... > > Consider: print Dumper( $animals, $digits ); > my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10); my_study (\@pets , \@numbers); sub my_study { my @animals = @{ shift @_ }; my @digits = @{ shift @_ }; # code for sub my_study } -- Don't stop where the ink does. Shawn -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How do I pass arrays into a subroutine
On 07/09/2013 13:43, Karol Bujaček wrote: print Dumper(@_);# just look how the @_ looks like Consider: print Dumper( \@_ ); my($animals, $digits) = @_; my @animals = @$animals; # dereference my @digits = @$digits; # dereference The comment is inaccurate. Why would you want to copy the arrays? print Dumper(@animals, @digits); # just look ... Consider: print Dumper( $animals, $digits ); -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How do I pass arrays into a subroutine
On 09/07/2013 01:11 PM, eventual wrote: Hi, In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets and @digits = @numbers. Thanks my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10); &study (@pets , @numbers); sub study { my (@animals, @digits) = (@_[0] , @_[1]); print "Animals = @animals\n"; print "Digits = @digits\n"; } Hi, You should use an array reference and dereference them in the subroutine. Also, do not use 'study', as it is defined already <http://perldoc.perl.org/functions/study.html>. Here is the code: use strict; use warnings; use Data::Dumper::Simple; my @pets = ('dogs', 'cats', 'horses'); my @numbers = (1..10); my_sub(\@pets, \@numbers); # array references are passed as arguments sub my_sub { print Dumper(@_);# just look how the @_ looks like my($animals, $digits) = @_; my @animals = @$animals; # dereference my @digits = @$digits; # dereference print Dumper(@animals, @digits); # just look ... print "Animals = @animals\n"; print "Digits = @digits\n"; } Best regards, Karol Bujacek -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: How do I pass arrays into a subroutine
Greetings, You cannot pass two arrays as the previous array will slurp (consume) all the elements. You need to go for references. Here is one way to do it [code] use strict; use warnings; my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10); &study (\@pets , \@numbers); sub study { my ($animals, $digits) = @_; print "Animals = @$animals\n"; print "Digits = @$digits\n"; } [/code] [output] Animals = dogs cats horses Digits = 1 2 3 4 5 6 7 8 9 10 [/output] best, Shaji --- Your talent is God's gift to you. What you do with it is your gift back to God. --- From: eventual To: "beginners@perl.org" Sent: Saturday, 7 September 2013 4:41 PM Subject: How do I pass arrays into a subroutine Hi, In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets and @digits = @numbers. Thanks my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10); &study (@pets , @numbers); sub study { my (@animals, @digits) = (@_[0] , @_[1]); print "Animals = @animals\n"; print "Digits = @digits\n"; }
Re: How do I pass arrays into a subroutine
Hi Eventual, On Sat, 7 Sep 2013 04:11:06 -0700 (PDT) eventual wrote: > Hi, > > In the example below, how do I pass @pets and @numbers into the subroutine so > that @animals = @pets and > @digits = @numbers. Please look into references and pass the arrays as references. See: http://perl-begin.org/topics/references/ (NOTE: perl-begin.org is a site I originated and still maintain.). Some comments about your code: > Thanks > > my @pets = ('dogs' , 'cats' , 'horses'); > my @numbers = (1..10); > > &study (@pets , @numbers); 1. There's already a built-in function called study so please pick another name: http://perldoc.perl.org/functions/study.html 2. Please don't call subroutines with ampersands ("&"): http://perl-begin.org/tutorials/bad-elements/#ampersand-in-subroutine-calls > > sub study { > > my (@animals, @digits) = (@_[0] , @_[1]); 1. Don't subscript arrays using @array[$idx]: http://perl-begin.org/tutorials/bad-elements/#at-array-for-subscripting 2. Don't use positional arguments: http://perl-begin.org/tutorials/bad-elements/#subroutine-arguments 3. Assigning to two arrays will cause the first array to swallow all the elements. Use references. Regards, Shlomi Fish -- ----- Shlomi Fish http://www.shlomifish.org/ http://www.shlomifish.org/humour/bits/Can-I-SCO-Now/ - "Can I SCO Now?" Buffy Summers does not really need stakes to slay vampires, because her kisses are deadly for them. And that includes those that she blows in the air. — http://www.shlomifish.org/humour/bits/facts/Buffy/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
How do I pass arrays into a subroutine
Hi, In the example below, how do I pass @pets and @numbers into the subroutine so that @animals = @pets and @digits = @numbers. Thanks my @pets = ('dogs' , 'cats' , 'horses'); my @numbers = (1..10); &study (@pets , @numbers); sub study { my (@animals, @digits) = (@_[0] , @_[1]); print "Animals = @animals\n"; print "Digits = @digits\n"; }
Re: Creating a Perl web site, how should I build this
On 07/03/13 10:13, Robert Freiberger wrote: I'm working on a work project where we are moving a few Perl scripts from a command line to a web page that will allow more users to access the tool. Basically it's a very simple script that takes an updated CSV feed, runs a internal test, then reports back the numbers from the test. Can you install the scripts on end users' machines, and let the users run them? David -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Creating a Perl web site, how should I build this
On Wed, Jul 03, 2013 at 10:13:19AM -0700, Robert Freiberger wrote: > Hello everyone, Hi, > I'm working on a work project where we are moving a few Perl > scripts from a command line to a web page that will allow more > users to access the tool. Basically it's a very simple script > that takes an updated CSV feed, runs a internal test, then > reports back the numbers from the test. > > Ideally, we would like to have this run from a web page instead > of from the command line as more people would like to access > the tool but don't want to give everyone shell access. But the > question is how should we build out this web page? In college I > did some CGI Perl writing but it looks like (I could be wrong) > that this is no longer the standard, and more people recommend > going with Dancer, Mojolicious or Catalyst. > > If anyone could provide suggestions to get started that would > be great. As an ASP Web application developer I am very interested in learning Perl's Web frameworks as much better alternatives. That said, I have been mostly unsuccessful in doing so. Perhaps mostly due to time constraints and lack of motivation. I have made some minor progress with Catalyst though that may help you move forward (or at least evaluate forward). Once you install the Catalyst developer module (e.g., cpanm Catalyst::Devel[1]) you should have a program installed called catalyst.pl which will allow you to create a new "application" skeleton (try the perldoc or --help for guidance with that tool). Once you have that skeleton you can run it using either the generated script/${app_name}_server.pl program within the application skeleton, or by using an external server, such as Starman (to the best of my knowledge, this is sort of the defacto standard "production" server to use; it has a more verbose name too, but Starman is indeed easier to remember ;). Starman isn't the only server option available, and you could probably even wire it up with more tradictional Web servers if you care to, but using Starman is probably the simpler option. You will have to evaluate its worthiness in production and overhead in administration (I haven't come close to this point yet). [1] I'm sort of winging this as it has been several months since I have touched anything to do with Catalyst... Time and motivation.. x( To run an instance of your skeleton application using the Starman server you must first install it (e.g., cpanm Starman). Then run it, passing a path to a .psgi file (which can I guess be thought of as the entry point for the PSGI i.e., Catalyst application). E.g., starman ${app_name}.psgi. That is as far as I have gotten unfortunately... It is based on an MVC structure so it will help to have an understanding of that (coming from ASP I probably have a broken understanding of that, but I digress... >:). All of this said, if others are right and you only have a simple program that will become a single Web page that just needs to run and generate some simple HTML output then it might well be easier to just hack up a CGI program and wire it up with whatever Web server is currently available. Your mileage may vary... And of course, there are many ways to do it. Just take care to sanitize user inputs, whatever you do... Regards, -- Brandon McCaig Castopulence Software <https://www.castopulence.org/> Blog <http://www.bamccaig.com/> perl -E '$_=q{V zrna gur orfg jvgu jung V fnl. }. q{Vg qbrfa'\''g nyjnlf fbhaq gung jnl.}; tr/A-Ma-mN-Zn-z/N-Zn-zA-Ma-m/;say' signature.asc Description: Digital signature
Re: Creating a Perl web site, how should I build this
You can make a standard everyday perl script, just make it print out HTML instead of text. Once you have that you can configure apache like this : ScriptAlias /script/ "/some/path/to/my/script.pl" If you then access the webserver http://ip.address/script/ you should get the HTML output of your script on your browser. On Wed, Jul 3, 2013 at 12:13 PM, Robert Freiberger wrote: > Hello everyone, > > I'm working on a work project where we are moving a few Perl scripts from > a command line to a web page that will allow more users to access the tool. > Basically it's a very simple script that takes an updated CSV feed, runs a > internal test, then reports back the numbers from the test. > > Ideally, we would like to have this run from a web page instead of from > the command line as more people would like to access the tool but don't > want to give everyone shell access. But the question is how should we build > out this web page? In college I did some CGI Perl writing but it looks like > (I could be wrong) that this is no longer the standard, and more people > recommend going with Dancer, Mojolicious or Catalyst. > > If anyone could provide suggestions to get started that would be great. > > Thanks, > Robert > > -- > Robert Freiberger > 510-936-1210 >
Re: Creating a Perl web site, how should I build this
On 07/03/2013 12:13 PM, Robert Freiberger wrote: Hello everyone, I'm working on a work project where we are moving a few Perl scripts from a command line to a web page that will allow more users to access the tool. Basically it's a very simple script that takes an updated CSV feed, runs a internal test, then reports back the numbers from the test. Ideally, we would like to have this run from a web page instead of from the command line as more people would like to access the tool but don't want to give everyone shell access. But the question is how should we build out this web page? In college I did some CGI Perl writing but it looks like (I could be wrong) that this is no longer the standard, and more people recommend going with Dancer, Mojolicious or Catalyst. If you are building a web *site* - with hundreds of pages linked to each other with a common theme and some variety of back-end data store, then the steep learning-curve of any of the frameworks would be well worth the investment. If you want to build a single web *page* where you feed it a file, it processes the data in some way, and produces an HTML report, I can see no good reason not to use something on the order of complexity of CGI. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Creating a Perl web site, how should I build this
Hello everyone, I'm working on a work project where we are moving a few Perl scripts from a command line to a web page that will allow more users to access the tool. Basically it's a very simple script that takes an updated CSV feed, runs a internal test, then reports back the numbers from the test. Ideally, we would like to have this run from a web page instead of from the command line as more people would like to access the tool but don't want to give everyone shell access. But the question is how should we build out this web page? In college I did some CGI Perl writing but it looks like (I could be wrong) that this is no longer the standard, and more people recommend going with Dancer, Mojolicious or Catalyst. If anyone could provide suggestions to get started that would be great. Thanks, Robert -- Robert Freiberger 510-936-1210
Re: how to make perl program run continue when i press control+s to pause screen output
Hi On 06/06/2013 06:25 PM, Jim Gibson wrote: > The program will keep running, but at some point, if the program is writing > bytes to the standard output stream, the buffer for that stream will fill up. > At that point, the program will block doing a write until the buffer has been > depleted and output can resume. Otherwise, some output would be lost. > > I was curious about this so i tried it out. It turns out that when I do ./script.pl | cat cat seems to add a big output buffer between your script and your console. So when i hit Ctrl-s the script will continue to run. The disadvantage is that I do not see the most recent output because cat does not immediately write the buffer to the terminal. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to make perl program run continue when i press control+s to pause screen output
I seriously think you've found a feature and you don't know what it is and just want to use it because it's there. Please read this: http://en.wikipedia.org/wiki/Software_flow_control After you're done, I recommend this in your shell rc: stty -ixon On Thu, Jun 6, 2013 at 12:49 PM, Robert Wohlfarth wrote: > On Thu, Jun 6, 2013 at 11:29 AM, Nemana, Satya wrote: >> >> Thanks Travis, Shlomi , Shawn, Luca, and James. >> >> The program pauses i.e does not run further when I press Cntrl –S >> >> When I press Ctrl-Q again, the program resumes excactly where it was when >> I hit cntrl-q. >> >> It is not a deamon, but a simple automation program and it is single >> threaded , goes on sequentially. >> >> I need to try out the programs that you suggested . >> >> However I don’t accept that the program will be running in the background >> when I press Ctrl+s. >> >> In the below example, once I start the program after seeing “i is 5” on >> the output, if I do ctrl+s, the output resumes at I is 6 even if I press >> ctrl+q after a minute or so. >> >> I expect it to print out till say i=65 during the 1 minute and I see the >> output all at once when I do ctrl+q >> >> I tried out a simple shell program and it also seems to be the same.(as >> the perl one) >> >> Is it that if the program is multi threaded or something like that that >> the program will keep to print even though I have paused the screen? > > > Your program doesn't write to the screen. Your program writes to a buffer, > which the operating system then copies onto the screen. Ctrl+S tells the > operating system to stop copying data from the buffer to the screen. It does > not stop your program from writing to the buffer. So your program keeps > running and writes the numbers sequentially into the buffer. > I think "copy" is the wrong way to think about it. I would say directed. But if that explanation works for someone, fine. > If you want to pause the actual program, then try Ctrl+Z. On a unix/linux > box that will work. See > http://www.gnu.org/software/bash/manual/bashref.html#Job-Control for more > information. > I sorta implied this with disown, but I shouldn't have - there's not much need to put jobs in the background anymore - use screen or tmux (it'll save you countless headaches - something locking a file and you end up fuser the file and find the pid is in the background of some terminal, vim complaining there's a swapfile and you end up redoing stuff because you didn't realize it was already open, leaving tail -F hainging out for days, etc). Use these old unix functions if you want, but it's unwise (humm, no - it's just plain idiotic) to do so. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to make perl program run continue when i press control+s to pause screen output
On Thu, Jun 6, 2013 at 11:29 AM, Nemana, Satya wrote: > Thanks Travis, Shlomi , Shawn, Luca, and James. > > The program pauses i.e does not run further when I press Cntrl –S > > When I press Ctrl-Q again, the program resumes excactly where it was when > I hit cntrl-q. > > It is not a deamon, but a simple automation program and it is single > threaded , goes on sequentially. > > I need to try out the programs that you suggested . > > However I don’t accept that the program will be running in the background > when I press Ctrl+s. > > In the below example, once I start the program after seeing “i is 5” on > the output, if I do ctrl+s, the output resumes at I is 6 even if I press > ctrl+q after a minute or so. > > I expect it to print out till say i=65 during the 1 minute and I see the > output all at once when I do ctrl+q > > I tried out a simple shell program and it also seems to be the same.(as > the perl one) > > Is it that if the program is multi threaded or something like that that > the program will keep to print even though I have paused the screen? > Your program doesn't write to the screen. Your program writes to a buffer, which the operating system then copies onto the screen. Ctrl+S tells the operating system to stop copying data from the buffer to the screen. It does not stop your program from writing to the buffer. So your program keeps running and writes the numbers sequentially into the buffer. When you press Ctrl+Q, it releases the operating system to copy from the buffer to the screen. The operating system then grabs everything from the buffer and dumps it onto the screen. So you see no interruption in the program output. If you want to pause the actual program, then try Ctrl+Z. On a unix/linux box that will work. See http://www.gnu.org/software/bash/manual/bashref.html#Job-Control for more information. -- Robert Wohlfarth
RE: how to make perl program run continue when i press control+s to pause screen output
Thanks Travis, Shlomi , Shawn, Luca, and James. The program pauses i.e does not run further when I press Cntrl –S When I press Ctrl-Q again, the program resumes excactly where it was when I hit cntrl-q. It is not a deamon, but a simple automation program and it is single threaded , goes on sequentially. I need to try out the programs that you suggested . However I don’t accept that the program will be running in the background when I press Ctrl+s. In the below example, once I start the program after seeing “i is 5” on the output, if I do ctrl+s, the output resumes at I is 6 even if I press ctrl+q after a minute or so. I expect it to print out till say i=65 during the 1 minute and I see the output all at once when I do ctrl+q I tried out a simple shell program and it also seems to be the same.(as the perl one) Is it that if the program is multi threaded or something like that that the program will keep to print even though I have paused the screen? So, when I press ctrl+q again all the buffered output is emptied out first and then the current output from the program. May be!! Sorry if it is out of topic for this forum. From: Travis Thornhill [mailto:madslashers2...@yahoo.com] Sent: 06 June 2013 17:04 To: Nemana, Satya Cc: beginners@perl.org Subject: Re: how to make perl program run continue when i press control+s to pause screen output On Jun 5, 2013, at 4:18, "Nemana, Satya" mailto:snem...@sonusnet.com>> wrote: Hi I am having a slight difficulty in getting this accomplished. When my perl program keeps running, I sometimes need to pause the screen output and check some things on the output. But, I want my program to still keep running while I pause the screen. (using ctrl+s on putty) But the program also is pausing.(I tested this with a simple program which prints number from 1-100 sleeping 1 second after each print , but the main program I am trying to get this working is much complex, so will try things here first before modifying the original program) Test Code : use strict; use warnings; for (my $i=1; $i <= 200; $i++) { print "\ni is $i"; sleep 1; } Please, could someone throw some light on which areas of perl to look at for this. I am not looking for a program, but specific areas where I have to do the reading. I will come back with the program once I can make out what to do for any suggestions. Thanks, Satya Your program should still be running, and it should still accept keyboard input. After ctrl-s, you just can't see any input/output. Try ctrl-q to recover.
Re: how to make perl program run continue when i press control+s to pause screen output
On Jun 6, 2013, at 9:04 AM, Travis Thornhill wrote: > > > On Jun 5, 2013, at 4:18, "Nemana, Satya" wrote: > >> Hi >> >> I am having a slight difficulty in getting this accomplished. >> When my perl program keeps running, I sometimes need to pause the screen >> output and check some things on the output. >> But, I want my program to still keep running while I pause the screen. >> (using ctrl+s on putty) >> But the program also is pausing.(I tested this with a simple program which >> prints number from 1-100 sleeping 1 second after each print , but the main >> program I am trying to get this working is much complex, so will try things >> here first before modifying the original program) >> >> > > Your program should still be running, and it should still accept keyboard > input. After ctrl-s, you just can't see any input/output. Try ctrl-q to > recover. The program will keep running, but at some point, if the program is writing bytes to the standard output stream, the buffer for that stream will fill up. At that point, the program will block doing a write until the buffer has been depleted and output can resume. Otherwise, some output would be lost. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to make perl program run continue when i press control+s to pause screen output
On Jun 5, 2013, at 4:18, "Nemana, Satya" wrote: > Hi > > I am having a slight difficulty in getting this accomplished. > When my perl program keeps running, I sometimes need to pause the screen > output and check some things on the output. > But, I want my program to still keep running while I pause the screen. > (using ctrl+s on putty) > But the program also is pausing.(I tested this with a simple program which > prints number from 1-100 sleeping 1 second after each print , but the main > program I am trying to get this working is much complex, so will try things > here first before modifying the original program) > > Test Code : > > use strict; > use warnings; > for (my $i=1; $i <= 200; $i++) > { > print "\ni is $i"; > sleep 1; > } > > Please, could someone throw some light on which areas of perl to look at for > this. > I am not looking for a program, but specific areas where I have to do the > reading. > I will come back with the program once I can make out what to do for any > suggestions. > > Thanks, > Satya > Your program should still be running, and it should still accept keyboard input. After ctrl-s, you just can't see any input/output. Try ctrl-q to recover.
Re: how to make perl program run continue when i press control+s to pause screen output
If it's a daemon, use something like start-stop-daemon or use something like Net::Daemon (search cpan). I prefer the former as I find it easier to debug but do have my programs create a pidfile vs having start-stop-daemon do it. If you just want it put in the background sometimes but generally want to interact with it (and don't use screen or tmux - shame on you for that but I'll try not to judge) see nohup or disown (disown being internal bash). There are also process management systems like gearman (I don't think you're here but just for completeness). On Jun 6, 2013 5:45 AM, "Luca Ferrari" wrote: > On Wed, Jun 5, 2013 at 1:18 PM, Nemana, Satya > wrote: > > Hi > > > > > > > > I am having a slight difficulty in getting this accomplished. > > > > When my perl program keeps running, I sometimes need to pause the screen > > output and check some things on the output. > > > > But, I want my program to still keep running while I pause the screen. > > (using ctrl+s on putty) > > > > But the program also is pausing.(I tested this with a simple program > which > > prints number from 1-100 sleeping 1 second after each print , but the > main > > program I am trying to get this working is much complex, so will try > things > > here first before modifying the original program) > > > > > > It is not clear what is the final aim, but having the program to go to > the background would suffice, assuming you have a way to redirect > output somewhere so that it will annoy you and assuming you don't have > to provide input during the process run. > > Luca > > -- > To unsubscribe, e-mail: beginners-unsubscr...@perl.org > For additional commands, e-mail: beginners-h...@perl.org > http://learn.perl.org/ > > >
Re: how to make perl program run continue when i press control+s to pause screen output
On Wed, Jun 5, 2013 at 1:18 PM, Nemana, Satya wrote: > Hi > > > > I am having a slight difficulty in getting this accomplished. > > When my perl program keeps running, I sometimes need to pause the screen > output and check some things on the output. > > But, I want my program to still keep running while I pause the screen. > (using ctrl+s on putty) > > But the program also is pausing.(I tested this with a simple program which > prints number from 1-100 sleeping 1 second after each print , but the main > program I am trying to get this working is much complex, so will try things > here first before modifying the original program) > > It is not clear what is the final aim, but having the program to go to the background would suffice, assuming you have a way to redirect output somewhere so that it will annoy you and assuming you don't have to provide input during the process run. Luca -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to make perl program run continue when i press control+s to pause screen output
Hi Satya, On Wed, 5 Jun 2013 11:18:14 + "Nemana, Satya" wrote: > Hi > > I am having a slight difficulty in getting this accomplished. > When my perl program keeps running, I sometimes need to pause the screen > output and check some things on the output. But, I want my program to still > keep running while I pause the screen. (using ctrl+s on putty) But the > program also is pausing.(I tested this with a simple program which prints > number from 1-100 sleeping 1 second after each print , but the main program I > am trying to get this working is much complex, so will try things here first > before modifying the original program) > > Test Code : > > use strict; > use warnings; > for (my $i=1; $i <= 200; $i++) > { > print "\ni is $i"; > sleep 1; > } > > Please, could someone throw some light on which areas of perl to look at for > this. I am not looking for a program, but specific areas where I have to do > the reading. I will come back with the program once I can make out what to do > for any suggestions. > Some thoughts: 1. You can try using a terminal multiplexer such as http://en.wikipedia.org/wiki/Tmux or http://en.wikipedia.org/wiki/GNU_Screen . 2. You can try running the program in the background - as a daemon. Regards, Shlomi Fish -- - Shlomi Fish http://www.shlomifish.org/ Perl Humour - http://perl-begin.org/humour/ Bugs are too afraid to reproduce on Chuck Norris’ computer. As a result, when he uses Microsoft Windows, it behaves just like a Linux system. — http://www.shlomifish.org/humour/bits/facts/Chuck-Norris/ Please reply to list if it's a mailing list post - http://shlom.in/reply . -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: how to make perl program run continue when i press control+s to pause screen output
Alternatively, output to a file, don't sleep (unless you really need to?), then tail that file in another console. (This would be for if you wanted to see different parts of the "printed" output while the program is still going.) James On Wed, Jun 5, 2013 at 5:18 AM, Nemana, Satya wrote: > Hi**** > > ** ** > > I am having a slight difficulty in getting this accomplished. > > When my perl program keeps running, I sometimes need to pause the screen > output and check some things on the output. > > But, I want my program to still keep running while I pause the screen. > (using ctrl+s on putty) > > But the program also is pausing.(I tested this with a simple program which > prints number from 1-100 sleeping 1 second after each print , but the main > program I am trying to get this working is much complex, so will try things > here first before modifying the original program) > > ** ** > > Test Code :**** > > ** ** > > use strict; > > use warnings; > > for (my $i=1; $i <= 200; $i++) > > { > > print "\ni is $i"; > > sleep 1; > > } > > ** ** > > Please, could someone throw some light on which areas of perl to look at > for this. > > I am not looking for a program, but specific areas where I have to do the > reading. > > I will come back with the program once I can make out what to do for any > suggestions. > > ** ** > > Thanks, > > Satya > > ** ** > > ** ** > > ** ** > > ** ** >
Re: how to make perl program run continue when i press control+s to pause screen output
Beginner to beginner here, but if you wanted to do two things at once, wouldn't you just need to use threads? http://perldoc.perl.org/threads.html (Disclaimer: Threads might be overkill, but it was the first thing I thought of.) James On Wed, Jun 5, 2013 at 5:18 AM, Nemana, Satya wrote: > Hi > > ** ** > > I am having a slight difficulty in getting this accomplished. > > When my perl program keeps running, I sometimes need to pause the screen > output and check some things on the output. > > But, I want my program to still keep running while I pause the screen. > (using ctrl+s on putty) > > But the program also is pausing.(I tested this with a simple program which > prints number from 1-100 sleeping 1 second after each print , but the main > program I am trying to get this working is much complex, so will try things > here first before modifying the original program) > > ** ** > > Test Code : > > ** ** > > use strict; > > use warnings; > > for (my $i=1; $i <= 200; $i++) > > { > > print "\ni is $i"; > > sleep 1;**** > > } > > ** ** > > Please, could someone throw some light on which areas of perl to look at > for this.**** > > I am not looking for a program, but specific areas where I have to do the > reading. > > I will come back with the program once I can make out what to do for any > suggestions. > > ** ** > > Thanks, > > Satya > > ** ** > > ** ** > > ** ** > > ** ** >
how to make perl program run continue when i press control+s to pause screen output
Hi I am having a slight difficulty in getting this accomplished. When my perl program keeps running, I sometimes need to pause the screen output and check some things on the output. But, I want my program to still keep running while I pause the screen. (using ctrl+s on putty) But the program also is pausing.(I tested this with a simple program which prints number from 1-100 sleeping 1 second after each print , but the main program I am trying to get this working is much complex, so will try things here first before modifying the original program) Test Code : use strict; use warnings; for (my $i=1; $i <= 200; $i++) { print "\ni is $i"; sleep 1; } Please, could someone throw some light on which areas of perl to look at for this. I am not looking for a program, but specific areas where I have to do the reading. I will come back with the program once I can make out what to do for any suggestions. Thanks, Satya
Re: Scripts in Padre do not run. Need step-by-step help in setting up, asall current procedures I have found have failed for me.
On 26/05/2013 14:28, Michael Rasmussen wrote: On Sat, May 25, 2013 at 04:19:27PM +0200, Dr.Ruud wrote: On 24/05/2013 22:25, Michael Goldsbie wrote: [...] I installed DWIM Perl [...] So after downloading and installing it, what's the next step? On http://dwimperl.com/ there is a link to 'Perl Tutorial', which has a link to 'Introduction 1. Install'. It mentions: "Go ahead, download the exe file and install it on your system. Before doing so, please make sure you don't have any other Perl installed." Try 'which perl' on the command prompt. What does it report? The OP states he's working in a Win7 environment, `which perl` is not available there. Ah indeed, I must have meant 'where', try "where perl". -- Ruud -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/