Re^2: Using system (); with Strawberry Perl
by LanX (Saint) on Nov 25, 2021 at 00:25 UTC
|
Actually that's similar to how I "migrated" from Bash to Perl back then ...
Cruel code! ;-)
| [reply] |
Re^2: Using system (); with Strawberry Perl
by Fletch (Bishop) on Nov 25, 2021 at 01:58 UTC
|
There was one "perl script" at $job several years back which was basically a bash script with every line wrapped in backticks . . . *shudder*
The cake is a lie.
The cake is a lie.
The cake is a lie.
| [reply] |
|
It's awful, but it does work :-)
| [reply] |
Re^2: Using system (); with Strawberry Perl
by cavac (Parson) on Nov 30, 2021 at 10:01 UTC
|
For me, a mixture of Bash and Perl sometimes makes sense when writing a quick proof of concept. If the main part of the code works out, i can always go to CPAN, find a module that fits my need, read the docs and then implement it.
But for a first try, it's often quicker to just calling wget than it is to install and use LWP::UserAgent. And for a PoC, it really doesn't matter if bash calls wget and then the perl script, or if the perl script calls wget when needed. It's just throw-away code anyway.
Case in point: Perl+PostgreSQL+GeoIP = Awesome! was my proof of concept, which then turned into GeoIP revisited. The proof of concept was ugly and was using external (command line) tools. But it quickly showed me what worked and what didn't. And it was "good enough" to post on PM to get some feedback from which i learned that i was using a deprecated GeoIP database version. Which then lead to a "Pure Perl" version that was nicer, but also more time intensive to implement.
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
| [reply] [d/l] |
|
There is a vast gulf between your proof of concept bash script and the OP's code!
I see your bash script, for example, calling:
rm GeoIPCountryCSV.zip
I do not see your Perl script calling:
system ("rm GeoIPCountryCSV.zip");
Look at the OP's code again. Have you ever seen anything like it?
I haven't, which is why I asked for the backstory behind it.
Sadly, it looks like we'll never know because the OP seems to have vanished (presumably forever) from the Perl Monks universe.
This is a tragedy because learning the backstory would make the description of the why behind this
code much more interesting when it's deservedly viewed by a wider audience.
BTW, given your interest in using a proof of concept, you might be interested in a three-part series
I wrote a few years ago: Building the Right Thing (Part I): Pretotyping
| [reply] |
|
Uhm, i grepped through parts of my codebase and there is this little gem:
system "aplay /home/cavac/src/pagecamel_dsky/masteralarm.wav &";
Turns out, playing sound on a Raspberry Pi 2(!) is hard, especially from Perl.
And yes, i have seen stuff like OP's code before. Many times. Many, many, times. Unfortunately. At least here on PM this is something that classes under "needs rewrite". I also develop Arduino stuff, and there a source code in that kind of quality would probably class as "made by an expert"...
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
| [reply] [d/l] [select] |
|
While I understand your sentiment and have done similar myself there is an inherent need to realise that doing such is pure hackery. In this particular case hadrons is shelling out to perform things like rename, unlink and so on which is arguably more work (because of shell escapes, etc) than just running the Perl built-ins. It is also highly relevant that it is this practice of shelling out alone which has given hadrons such problems that they have needed to come here seeking advice in the first place.
But for a first try, it's often quicker to just calling wget than it is to install and use LWP::UserAgent.
Can't say I agree. If LWP isn't already installed you may as well do so now because you are going to need it sooner or later. It's also pretty simple to use. However, if even that is too much trouble, then consider HTTP::Tiny which is in core so you already have it.
| [reply] |
|
LWP/wget might not be the best example, i agree. (Although, unless something has changed in the last year or so, the installed LWP doesn't work by default because the ::https module is missing).
perl -e 'use Crypt::Digest::SHA256 qw[sha256_hex]; print substr(sha256_hex("the Answer To Life, The Universe And Everything"), 6, 2), "\n";'
| [reply] [d/l] |
Re^2: Using system (); with Strawberry Perl
by hadrons (Novice) on Nov 25, 2021 at 17:58 UTC
|
I'm aware its poor programming, but the results work | [reply] |
|
| [reply] |
|
Well, sort of :-) ... it's an issue of the platform. If I could stick to cygwin it would be fine, but I needed to move the script to a Windows based on. But, I'm not going to deny I'm at a disadvantage defending this coding either.
| [reply] |
|
| [reply] |
|
|
| [reply] |