Hacking a script (makemenu.pl)

Discussion in 'Perl Misc' started by Frank Louden, Sep 5, 2005.

  1. Frank Louden

    Frank Louden Guest

    Hi. Infrequent hacker here.

    (Originally posted to alt.comp.lang.perl. Not much happening over there!)
    (OK, then to comp.lang.perl where a kind soul redirected me.)

    I've spent the last two days trying to hack H. Churchyard's makemenu.pl so
    it will work on my WinME PC. I've got lots of hair but I won't have for
    long.

    If there is anyone out there that knows this script, I think I might learn
    quite a bit by hacking my way thru this one but I could sure use some help.

    I'm not looking for a working script or someone to do it for me. I'd just
    like to understand what's going on here and why I am having such a tough
    time getting very far with this. I'm using Activestate's perl, v5.8.6 built
    for MSWin32-x86-multi-thread.

    There are two "eval" lines here...

    eval "exec /usr/local/bin/perl -S $0 $*" if $running_under_some_shell;

    and...

    eval '$'.$1.'$2;' while $ARGV[0] =~ /^(title=|toc=|dirprefix=)(.*)/ &&
    shift;

    The first is unnecessary (I think) and the second is extracting info from
    the command line.

    I don't know how advanced this script might be but it seems to be using
    lot's of tricks that aren't taught in "Learning Perl on Win32 Systems". ;^)

    Anyway, if there is someone that can spare the time to share some of their
    knowledge with me, I'd be grateful.

    I would attempt to contact the author of this script if I knew how. I've
    used it "as is" on Linux and it works quite well for what I am wanting to
    do.

    Here's the error I get...

    F:\Programming\Perl\HTML Menu Project>perl -d test2.pl title="My Menu" toc=1
    *.htm > My_Menu.htm
    Win32::OLE operating in debugging mode: _Unique => 1
    Can't open *.htm: No such file or directory at test2.pl line 12.

    And I have several small HTML files with the ".htm" extension in this
    directory.

    I've stripped this script down to what I think is the barest essentials for
    testing. I don't expect this fragment to do anything I'm just trying to get
    over a hump. I hit the "while (<>)" line and I get nothing. Here's what I
    have at this time...

    $title = ''; $toc = 0; $dirprefix = '';
    eval '$'.$1.'$2;' while $ARGV[0] =~ /^(title=|toc=|dirprefix=)(.*)/ &&
    shift;
    $[ = 1; # set array base to 1
    $\ = "\n"; # set output record separator
    foreach $X (@ARGV) {
    if ($X =~ /^[^=]+=/) {
    print STDERR "Apparent misspelled or badly-placed command-line
    option $\
    &";
    print STDERR "Attempting to continue anyway...";}}
    $accum = ''; $haccum = '';
    $xRS = $/;
    #
    while (<>) {
    if ($_ =~ /$xRS$/o) {chop;} # strip record separator
    if (($.-$FNRbase) == 1) {
    if ($. == 1) {
    if (!$title) {
    $title = 'Menu for HTML files';}
    print "<html><head><title>$title</title></head>";
    print "<body><h1>$title</h1><hr><ul>";}
    else {
    if ($toc) {
    &liout();}}
    $hlevel = 0;}

    };

    Thanks in advance.

    Raffles
    Frank Louden, Sep 5, 2005
    #1
    1. Advertising

  2. Frank Louden wrote:
    > ...
    > F:\Programming\Perl\HTML Menu Project>perl -d test2.pl title="My Menu" toc=1
    > *.htm > My_Menu.htm
    > Win32::OLE operating in debugging mode: _Unique => 1
    > Can't open *.htm: No such file or directory at test2.pl line 12.
    > ...


    Maybe someone will correct me if I am wrong, but it appears that the DOS
    prompt does not suppliment the asterisks for you like UNIX shells do; if
    you 'echo *', you will just see '*', not all the files in the directory
    like you would on a UNIX shell. You'll have to do the supplimentation
    manually, perhaps by using glob().

    Again, I could be wrong, but this seems to be the case here.

    -Willie



    ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
    http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
    ----= East and West-Coast Server Farms - Total Privacy via Encryption =----
    Willie Wilson, Sep 5, 2005
    #2
    1. Advertising

  3. Frank Louden wrote:

    > Hi. Infrequent hacker here.
    >
    > (Originally posted to alt.comp.lang.perl. Not much happening over there!)
    > (OK, then to comp.lang.perl where a kind soul redirected me.)
    >
    > I've spent the last two days trying to hack H. Churchyard's makemenu.pl so
    > it will work on my WinME PC. I've got lots of hair but I won't have for
    > long.


    You didn't provide a link so I had to google. When I did so, the pages
    I came up with were discussing "htmlchek version 4.0, January 17 1995".
    And this was documentation -- not the code itself.

    While I suspect there are probably readers of this list who are familiar
    with this script, I frankly suspect that better tools have been
    developed in the last ten-and-a-half years. What task are you trying to
    accomplish?

    Jim Keenan
    James E Keenan, Sep 5, 2005
    #3
  4. Frank Louden

    Frank Louden Guest

    Thanks Willie and Jim. This version of perl allows globbing so I expected it
    to work just fine with the <> operator. But, there are so many differences
    between MSWindoze and Unix/Linux systems I thought the developers of this
    distribution of perl would accomodate Win32's crippled OS.


    "James E Keenan" <> wrote in message
    news:35NSe.7569$aG.1028@trndny01...
    > Frank Louden wrote:
    >
    > > Hi. Infrequent hacker here.
    > >
    > > (Originally posted to alt.comp.lang.perl. Not much happening over

    there!)
    > > (OK, then to comp.lang.perl where a kind soul redirected me.)
    > >
    > > I've spent the last two days trying to hack H. Churchyard's makemenu.pl

    so
    > > it will work on my WinME PC. I've got lots of hair but I won't have for
    > > long.

    >
    > You didn't provide a link so I had to google. When I did so, the pages
    > I came up with were discussing "htmlchek version 4.0, January 17 1995".
    > And this was documentation -- not the code itself.
    >
    > While I suspect there are probably readers of this list who are familiar
    > with this script, I frankly suspect that better tools have been
    > developed in the last ten-and-a-half years. What task are you trying to
    > accomplish?
    >
    > Jim Keenan
    >
    >
    Frank Louden, Sep 5, 2005
    #4
  5. Frank Louden wrote:
    > Hi. Infrequent hacker here.
    >
    > (Originally posted to alt.comp.lang.perl. Not much happening over there!)
    > (OK, then to comp.lang.perl where a kind soul redirected me.)
    >
    > I've spent the last two days trying to hack H. Churchyard's makemenu.pl so
    > it will work on my WinME PC. I've got lots of hair but I won't have for
    > long.
    >
    > If there is anyone out there that knows this script, I think I might learn
    > quite a bit by hacking my way thru this one but I could sure use some help.
    >
    > I'm not looking for a working script or someone to do it for me. I'd just
    > like to understand what's going on here and why I am having such a tough
    > time getting very far with this. I'm using Activestate's perl, v5.8.6 built
    > for MSWin32-x86-multi-thread.


    It looks like makemenu.pl was created using the a2p program (Awk to Perl
    translator) on makemenu.awk.

    perldoc a2p


    If you have a more recent version of a2p it should produce a more up-to-date
    perl program.


    > There are two "eval" lines here...
    >
    > eval "exec /usr/local/bin/perl -S $0 $*" if $running_under_some_shell;


    This is superfluous in a perl program if the first line
    (#!/usr/local/bin/perl) is the correct location of perl.


    > and...
    >
    > eval '$'.$1.'$2;' while $ARGV[0] =~ /^(title=|toc=|dirprefix=)(.*)/ &&
    > shift;


    It appears that this is just sort-of imitating the perl '-s' command line switch.


    > The first is unnecessary (I think) and the second is extracting info from
    > the command line.
    >
    > I don't know how advanced this script might be but it seems to be using
    > lot's of tricks that aren't taught in "Learning Perl on Win32 Systems". ;^)
    >
    > Anyway, if there is someone that can spare the time to share some of their
    > knowledge with me, I'd be grateful.
    >
    > I would attempt to contact the author of this script if I knew how. I've
    > used it "as is" on Linux and it works quite well for what I am wanting to
    > do.
    >
    > Here's the error I get...
    >
    > F:\Programming\Perl\HTML Menu Project>perl -d test2.pl title="My Menu" toc=1
    > *.htm > My_Menu.htm
    > Win32::OLE operating in debugging mode: _Unique => 1
    > Can't open *.htm: No such file or directory at test2.pl line 12.


    DOS/Windows command processor (command.com/cmd.exe) does not expand wildcard
    characters (like * or ?) so your perl program is trying to process the literal
    file name '*.htm'.

    perldoc -f glob
    perldoc File::Glob




    John
    --
    use Perl;
    program
    fulfillment
    John W. Krahn, Sep 5, 2005
    #5
  6. Frank Louden

    Frank Louden Guest

    Thank you John.

    Actually I did get the program to work late last night but I have to load
    @ARGV inside of the script. This is fine as my use for the script is to
    build a menu of all of the HTML files inside of a directory and setting ARGV
    to "*.htm*" in the script just means that I loose some of the options since
    I can't get my info from the command line. That's all right for now. I am
    sure you're right about this difficulty being OS related. Unfortunately, a
    lot of us have to work on MS systems.

    Thanks to all for your suggestions and help.

    "John W. Krahn" <> wrote in message
    news:_QPSe.216630$9A2.71758@edtnps89...
    > Frank Louden wrote:
    > > Hi. Infrequent hacker here.
    > >
    > > (Originally posted to alt.comp.lang.perl. Not much happening over

    there!)
    > > (OK, then to comp.lang.perl where a kind soul redirected me.)
    > >
    > > I've spent the last two days trying to hack H. Churchyard's makemenu.pl

    so
    > > it will work on my WinME PC. I've got lots of hair but I won't have for
    > > long.
    > >
    > > If there is anyone out there that knows this script, I think I might

    learn
    > > quite a bit by hacking my way thru this one but I could sure use some

    help.
    > >
    > > I'm not looking for a working script or someone to do it for me. I'd

    just
    > > like to understand what's going on here and why I am having such a tough
    > > time getting very far with this. I'm using Activestate's perl, v5.8.6

    built
    > > for MSWin32-x86-multi-thread.

    >
    > It looks like makemenu.pl was created using the a2p program (Awk to Perl
    > translator) on makemenu.awk.
    >
    > perldoc a2p
    >
    >
    > If you have a more recent version of a2p it should produce a more

    up-to-date
    > perl program.
    >
    >
    > > There are two "eval" lines here...
    > >
    > > eval "exec /usr/local/bin/perl -S $0 $*" if $running_under_some_shell;

    >
    > This is superfluous in a perl program if the first line
    > (#!/usr/local/bin/perl) is the correct location of perl.
    >
    >
    > > and...
    > >
    > > eval '$'.$1.'$2;' while $ARGV[0] =~ /^(title=|toc=|dirprefix=)(.*)/ &&
    > > shift;

    >
    > It appears that this is just sort-of imitating the perl '-s' command line

    switch.
    >
    >
    > > The first is unnecessary (I think) and the second is extracting info

    from
    > > the command line.
    > >
    > > I don't know how advanced this script might be but it seems to be using
    > > lot's of tricks that aren't taught in "Learning Perl on Win32 Systems".

    ;^)
    > >
    > > Anyway, if there is someone that can spare the time to share some of

    their
    > > knowledge with me, I'd be grateful.
    > >
    > > I would attempt to contact the author of this script if I knew how. I've
    > > used it "as is" on Linux and it works quite well for what I am wanting

    to
    > > do.
    > >
    > > Here's the error I get...
    > >
    > > F:\Programming\Perl\HTML Menu Project>perl -d test2.pl title="My Menu"

    toc=1
    > > *.htm > My_Menu.htm
    > > Win32::OLE operating in debugging mode: _Unique => 1
    > > Can't open *.htm: No such file or directory at test2.pl line 12.

    >
    > DOS/Windows command processor (command.com/cmd.exe) does not expand

    wildcard
    > characters (like * or ?) so your perl program is trying to process the

    literal
    > file name '*.htm'.
    >
    > perldoc -f glob
    > perldoc File::Glob
    >
    >
    >
    >
    > John
    > --
    > use Perl;
    > program
    > fulfillment
    Frank Louden, Sep 5, 2005
    #6
  7. Frank Louden

    Frank Louden Guest

    For anyone interested, the scripts for this program are available at...

    http://www.crossmyt.com/hc/htmlchek/htmlchek.html

    ....near the bottom of the page.

    It's old software. But for me, I expect a good lesson in regular expressions
    and some other stuff.

    Thanks again y'all!



    "Frank Louden" <> wrote in message
    news:...
    > Hi. Infrequent hacker here.
    >
    > (Originally posted to alt.comp.lang.perl. Not much happening over there!)
    > (OK, then to comp.lang.perl where a kind soul redirected me.)
    >
    > I've spent the last two days trying to hack H. Churchyard's makemenu.pl so
    > it will work on my WinME PC. I've got lots of hair but I won't have for
    > long.
    >
    > If there is anyone out there that knows this script, I think I might learn
    > quite a bit by hacking my way thru this one but I could sure use some

    help.
    >
    > I'm not looking for a working script or someone to do it for me. I'd just
    > like to understand what's going on here and why I am having such a tough
    > time getting very far with this. I'm using Activestate's perl, v5.8.6

    built
    > for MSWin32-x86-multi-thread.
    >
    > There are two "eval" lines here...
    >
    > eval "exec /usr/local/bin/perl -S $0 $*" if $running_under_some_shell;
    >
    > and...
    >
    > eval '$'.$1.'$2;' while $ARGV[0] =~ /^(title=|toc=|dirprefix=)(.*)/ &&
    > shift;
    >
    > The first is unnecessary (I think) and the second is extracting info from
    > the command line.
    >
    > I don't know how advanced this script might be but it seems to be using
    > lot's of tricks that aren't taught in "Learning Perl on Win32 Systems".

    ;^)
    >
    > Anyway, if there is someone that can spare the time to share some of their
    > knowledge with me, I'd be grateful.
    >
    > I would attempt to contact the author of this script if I knew how. I've
    > used it "as is" on Linux and it works quite well for what I am wanting to
    > do.
    >
    > Here's the error I get...
    >
    > F:\Programming\Perl\HTML Menu Project>perl -d test2.pl title="My Menu"

    toc=1
    > *.htm > My_Menu.htm
    > Win32::OLE operating in debugging mode: _Unique => 1
    > Can't open *.htm: No such file or directory at test2.pl line 12.
    >
    > And I have several small HTML files with the ".htm" extension in this
    > directory.
    >
    > I've stripped this script down to what I think is the barest essentials

    for
    > testing. I don't expect this fragment to do anything I'm just trying to

    get
    > over a hump. I hit the "while (<>)" line and I get nothing. Here's what I
    > have at this time...
    >
    > $title = ''; $toc = 0; $dirprefix = '';
    > eval '$'.$1.'$2;' while $ARGV[0] =~ /^(title=|toc=|dirprefix=)(.*)/ &&
    > shift;
    > $[ = 1; # set array base to 1
    > $\ = "\n"; # set output record separator
    > foreach $X (@ARGV) {
    > if ($X =~ /^[^=]+=/) {
    > print STDERR "Apparent misspelled or badly-placed command-line
    > option $\
    > &";
    > print STDERR "Attempting to continue anyway...";}}
    > $accum = ''; $haccum = '';
    > $xRS = $/;
    > #
    > while (<>) {
    > if ($_ =~ /$xRS$/o) {chop;} # strip record separator
    > if (($.-$FNRbase) == 1) {
    > if ($. == 1) {
    > if (!$title) {
    > $title = 'Menu for HTML files';}
    > print "<html><head><title>$title</title></head>";
    > print "<body><h1>$title</h1><hr><ul>";}
    > else {
    > if ($toc) {
    > &liout();}}
    > $hlevel = 0;}
    >
    > };
    >
    > Thanks in advance.
    >
    > Raffles
    >
    >
    >
    Frank Louden, Sep 5, 2005
    #7
  8. Frank Louden

    Joe Smith Guest

    Frank Louden wrote:
    > Thanks Willie and Jim. This version of perl allows globbing so I expected it
    > to work just fine with the <> operator. But, there are so many differences
    > between MSWindoze and Unix/Linux systems I thought the developers of this
    > distribution of perl would accomodate Win32's crippled OS.


    Which perl are you using?


    C:\Documents and Settings\jms>dir/w *.pl
    bcm-route.pl editorlog.pl ls-temp.pl prog1.pl temp.pl

    C:\Documents and Settings\jms>perl -le "print qq{@ARGV}" *.pl
    *.pl

    C:\Documents and Settings\jms>perl -v
    This is perl, v5.8.7 built for MSWin32-x86-multi-thread
    Binary build 813 [148120] provided by ActiveState

    That version of perl works just fine with the <> operator.
    It's @ARGV that is different.
    -Joe
    Joe Smith, Sep 6, 2005
    #8
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. RA
    Replies:
    12
    Views:
    1,522
    Kevin Spencer
    Aug 3, 2004
  2. paul Z

    hacking /dev/audio

    paul Z, Mar 7, 2004, in forum: C Programming
    Replies:
    2
    Views:
    377
    Malcolm
    Mar 7, 2004
  3. Hugh Macdonald

    Hacking the scope to pieces

    Hugh Macdonald, May 24, 2005, in forum: Python
    Replies:
    4
    Views:
    318
  4. Darrell Thompson
    Replies:
    0
    Views:
    79
    Darrell Thompson
    Aug 14, 2003
  5. e.expelliarmus
    Replies:
    1
    Views:
    250
    A. Sinan Unur
    Sep 25, 2007
Loading...

Share This Page