The output of commands like "find ... -print0" is a list of NUL-delimited names. This snippet shows a quick way to get those into @ARGV for processing.
{ local $/ = "\0"; chomp(@ARGV = <STDIN>) or exit; }

Replies are listed 'Best First'.
Re: Read a list of NUL-delimited names from STDIN to be processed
by ambrus (Abbot) on Nov 23, 2005 at 20:01 UTC

    When I read nul-delimited lines from find or xargs, I usually do that with the -0 switch (which is equivalent to $/ = "\0";), and I don't chomp the data as the extra nul byte doesn't hurt after filenames.

      and I don't chomp the data as the extra nul byte doesn't hurt after filenames.

      Well I think it could hurt in case of a Null Byte Poisoning

      Let's say you would have a null terminated file name, and would like to append the name with another string (like an index or whatever)
      Consider the following piece of code:

      #!/usr/bin/perl -w use strict; my $fname = "aaa.txt\0bla"; print "NAME: $fname\n"; if ( $fname =~ /\0/ ) { open( F, ">$fname" ) || die "could not open $fname, reason: $!"; close(F); } else { print "No NULL BYTE in $fname\n"; }
      It doesn't do what you would expect it to do, right?

      Of course, I may be dead wrong ....

      Dodge This!