please dont rip this site

Perl Function "angle brackets"

<filehandle>
Returns a line of data from the file. When reading anything in, (file, console, etc...) it is automatically split in to parts delimited by the $/ value. Note that it will ONLY RETURN ONE LINE (up to a linefeed) even if the file is in binmode if $/ is not set to something other than its default value of a linefeed. undef $/ to read the entire file in one shot with no splitting. Set $/ to an ordinal number to read a specific number of charicters each time (fixed record size)
It would appear that things like <*.txt> act as though they are opening and reading the directory listing as though it was a file using something called (I'm not making this up!) glob()

See also:

Samples

reading an entire binary file (line by line) without loosing the "linefeeds" in the binary data into a variable so you can tweek it before writing it back out.
$old = $file;
$new = "$file.bak";
$bak = "$file.orig";
open(OLD, "< $old")         or die "can't open $old: $!";
binmode OLD;
open(NEW, "> $new")         or die "can't open $new: $!";
binmode NEW;
$mydata = "";
while (<OLD>) {
  $mydata .= $_;
  }
#now you can do stuff to $mydata;
#be sure to use s on the end of any regexps so that it will work across "lines"
#and use g on the end to replace all occurances
#e.g. s/old text/new text/sg
(print NEW $mydata)          or die "can't write to $new: $!";
close(OLD);
close(NEW;
rename($old, $bak)
rename($new, $old)

errr... no. no. no. see perlfaq6.html i'm having trouble matching over more than one line. what's wrong which basically says that if you put in

undef $/;

you will read in the entire thing in one shot rather than line by line and binmode shouldn't matter then. Also, you can set $/ to an ORDINAL number and it will read only that number of bytes.

See:


file: /Techref/language/perl/anglebrackets.htm, 3KB, , updated: 2014/4/1 16:08, local time: 2024/11/24 02:31,
TOP NEW HELP FIND: 
3.14.246.52:LOG IN

 ©2024 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions?
Please DO link to this page! Digg it! / MAKE!

<A HREF="http://sxlist.com/TECHREF/language/perl/anglebrackets.htm"> Perl Function "angle brackets"</A>

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type a nice message (short messages are blocked as spam) in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.


Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

 

Welcome to sxlist.com!


Site supported by
sales, advertizing,
& kind contributors
just like you!

Please don't rip/copy
(here's why

Copies of the site on CD
are available at minimal cost.
 

Welcome to sxlist.com!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .