in reply to Re: Text File Parsing / Homegrown Template
in thread text file parsing

"Your technique of pushing things onto @ARGV is clever, and yet at the same time kind of disturbing."

Looks like the code i gave out at (jeffa) Re: Print contents of a range of text files to browser (was: text files). That is a trick i picked up from merlyn at •Re: Re: Listing Files.

"If this were production code, I'd suggest doing something a little more formalised."

Let's see what merlyn has to say about that: •Re: Re: •Re: Re: Listing Files. I'm with merlyn on this one.

UPDATE:
Although ... i really do believe that using @ARGV in this manner is what is causing the script to hang - if any of the the conditions that cause a die in the code above are met without that die - the code will hang. Maybe Anony should be a bit more careful and explicitly open the files like you suggest.

Myself, i will still use that technique anyway. You just have to know what you are doing. ;)

jeffa

Scissors are for running
  • Comment on (jeffa) 3Re: Text File Parsing / Homegrown Template

Replies are listed 'Best First'.
Re^4: Text File Parsing / Homegrown Template
by tadman (Prior) on Jun 18, 2002 at 22:22 UTC
    I can see where merlyn is coming from. It is true that @ARGV and <> are intertwined, that this behaviour is a fundamental property of Perl, but even so, it's still kind of odd.

    This use of @ARGV is that sometimes irritating "Swiss-Army" property of Perl. Sure, it slices and dices, but just because you can doesn't mean you should. merlyn has his reasons for promoting it, I'm sure, but I'm not totally sold.

    The thing I don't like about it is that, apart from smelling a little too much of shell-script programming, it isn't re-entrant. If you need to process a sub-file in the same manner, things are going to get a little hairy because you're using a global. You could make it local, presumably, but I was under the impression that local was going to walk the plank in short order.

    What I'd probably do is sub-class IO::File and make something that could read from a group (or glob) of files. That way the "file chaining" stuff is safely contained.
      but I was under the impression that local was going to walk the plank in short order.
      A mistaken impression, I can assure you. Not only will it work through the end of product life in Perl5, but it will also continue to work under the new name temp in Perl6.

      -- Randal L. Schwartz, Perl hacker