|
|
| go ahead... be a heretic | |
| PerlMonks |
very new to perl; suggestions for porting this shell script to perl?by sinusoid (Initiate) |
| on May 27, 2011 at 19:39 UTC ( #907057=perlquestion: print w/ replies, xml ) | Need Help?? |
|
sinusoid has asked for the
wisdom of the Perl Monks concerning the following question:
I have very limited experience in any sort of scripting other than linux shell scripts. I wrote a shell script to generate a menu for a linux window manager called pekwm, but it wasn't quite fast enough to be used as a "dynamic menu entry" so i've been using it to generate a text file read by the menu on a per-need basis. Then i came across perl and noticed how much more speed the scripts seem to be capable of achieving and decided to try to port the shell script to perl. I do not want to add any functionality, i just have a feeling it could be much more efficient, as i wrote based on nothing but a few relevant examples I came across. For a more detailed description on how this script is supposed to work see the very bottom. First i'll post the shell script (which i don't believe needs any refinement, followed by what i've managed in perl..
Shell Script:
One thing I was unable to figure out how to emulate in perl was the option to specify a set of expressions or line numbers fuctioning as the start/stop boundaries for where the string search/replace should happen. this was achieved in the shell script above using "name=`sed -n '1,/^Name=/ s/^Name=//p' <$CATMATCH`", where "1,/^Name=/" specifies the boundaries. Perl Script:
The script generates a menu (actually, a part of a menu) by matching the desired list of categories (which are also used as names for each sub-menu entry during generation) against those specified in the /usr/share/applications/*.desktop files. When a match is found, it reports the name of which xxx.desktop file the match occured and extracts from that file the name of the application and the command used to run it. It then prints the necessary menu syntax stuff, adding from variables the name of the sub-menu (taken from the matched category), the name of the application (taken from the name extracted from the xxx.desktop file), and the command used to execute that application (also extracted from the xxx.desktop file) for each particular file of each particular submenu. Thanks in advance for any sort of help you can give!
Back to
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||||