in reply to Re^10: Should Modules Do I/O?
in thread Should Modules Do I/O?

In this context, "user", refers to the user of the API. Ie. The programmer who's code calls the API, as opposed to the programmer who codes the API. Perhaps you will re-read the post in that light?


Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
Lingua non convalesco, consenesco et abolesco.
Rule 1 has a caveat! -- Who broke the cabal?

Replies are listed 'Best First'.
Re^12: Should Modules Do I/O?
by Tanktalus (Canon) on Mar 19, 2005 at 15:06 UTC

    Actually, I must be missing the distinction. You're saying that the programmer would use the command line invocation ... programmatically? Something like...

    system("archive_tar.pl --tar $tarball --destination_path $some_path" +);
    instead of...
    $tar->extract($some_path);
    ? I'm not sure I see how this is a clear winner.

      Now we are getting silly, but ... I'll play :)

      That would be more like:

      system( "tar -xvf $tarball $some_path" ) == 0 or die "tar failed: $?";

      versus

      use Archive::Tar; my $tar = Archive::Tar->new( $tarball ) or die "Failed to open $tarball : $!"; $tar->extract( $some_path ) or die "Failed to extract $some_path: $!";

      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      Lingua non convalesco, consenesco et abolesco.
      Rule 1 has a caveat! -- Who broke the cabal?

        You're talking about silliness ... and I'm getting more confused.

        Heaven forbid that the tarball (or somepath) has a space or pipe or < or > or some other funny character ($ on unix, %..% on windows, etc.) which the shell will play havoc with. Easy enough to fix, right? What if the windows version takes different parameters than the unix version? (Some tar's on Linux have not liked the dash for the tar commands, for example.) Having had to write my perl for Windows (ia32, ia64, x86-64), AIX, Sun, HP (PA/RISC, ia64), and Linux (ia32, ia64, x86-64, ppc64, s390, s390x), (not with Archive::Tar, but with other modules) I am ever so thankful that these modules exist, provide a single cross-platform interface, and provide a simple interface that allows me to concentrate on getting my work done rather than dealing with the short-lived filehandles, or with commandlines to other software that keeps changing from platform to platform. The only system software I deal with now is stuff that is platform-specific anyway (e.g., Windows Installer). And even that, I'm looking to use OLE or something.

        I suppose the point is - your first example doesn't work for a tarball named "My Data.tar" which is supposed to go into "C:\My Documents\My Excel Spreadsheets". The point is not that this is something easy to fix - the point is that it is something easy to get wrong. And that's what modules are there for - helping us get it right by handling all the "silly" cases.

        (Oh, and, just as another point on how easy it is to get wrong: you missed the "-C" for $some_path. I used "archive_tar.pl" on purpose to avoid the annoying tar commandline syntax ;-})