JP Vossen on 19 Nov 2007 22:48:29 -0000


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] Perl backticks/system question


Date: Mon, 19 Nov 2007 13:59:05 -0500
From: Jon Nelson <lists@linuxnotes.net>

I tried using open() and got the same results.  The script is really
nothing but a one-liner that caused more errors when I tried to run it
from within perl:

    #!/bin/sh
    IFS=$"\n"
    strings $1 | egrep -i "^[a-z]{1}:.*$2$"

Style note: the IFS=$'' (or presumably IFS=$"") notation is bash and ksh specific. It's not portable, thus using #!/bin/sh will fail on non-Linux systems, and I'm not sure what dash (which is /bin/sh on Ubuntu and soon Debian) will do. It's also unclear to the reader since the script requires bash but specified bourne. The shebang line should be "#!/bin/bash" or for best portability "#!/usr/bin/env bash".


Now that I got that off my chest...  :-)


How about something more like this in your Perl:

	$fileLoc = 'file_location_not_found__bummer';
	my @strings = `strings $fullPath`;
	for (@strings) { $fileLoc = $_ if m/^[a-z]{1}:.*${line}$/; }

There's probably a fancier way to do this, but that worked for me using a simple example I made up. The "error checking" if the "grep" doesn't get a hit is a bit primitive. I'd guess there's probably a CPAN module for 'strings' so you could do everything in Perl since the `` sub-shell is ugly. But I'd probably do it using `` also, since it's easy to write, clear to read and doesn't require messing with CPAN.

HTH,
JP
----------------------------|:::======|-------------------------------
JP Vossen, CISSP            |:::======|        jp{at}jpsdomain{dot}org
My Account, My Opinions     |=========|      http://www.jpsdomain.org/
----------------------------|=========|-------------------------------
Microsoft has single-handedly nullified Moore's Law.
Innate design flaws of Windows make a personal firewall, anti-virus
and anti-malware software mandatory. The resulting software arms race
has effectively flattened Moore's Law on hardware running Windows.
___________________________________________________________________________
Philadelphia Linux Users Group         --        http://www.phillylinux.org
Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce
General Discussion  --   http://lists.phillylinux.org/mailman/listinfo/plug