Perl: backslash in front of integer like \32768


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl: backslash in front of integer like \32768
# 1  
Old 01-20-2014
Question Perl: backslash in front of integer like \32768

In Perl, what does a backslash preceding an integer do like \32768 ?

The $/ section of perlvar writes:
Code:
local $/ = \32768; # or \"32768", or \$var_containing_32768

How is \32768 different from just 32768 without backslash?

I do not understand the backslashes in \"32768" and \$var_containing_32768, either.

Many thanks, in advance.
# 2  
Old 01-20-2014
preceding it with a backslash makes it a reference to the number, which in this case has the effect of setting the max record length, this is for filesystems with record based files rather than line based files.
Code:
 Setting $/ to a reference to an integer, scalar containing an
               integer, or scalar that's convertible to an integer will
               attempt to read records instead of lines, with the maximum
               record size being the referenced integer. So this:

                   local $/ = \32768; # or \"32768", or \$var_containing_32768
                   open my $fh, "<", $myfile or die $!;
                   local $_ = <$fh>;

               will read a record of no more than 32768 bytes from FILE. If
               you're not reading from a record-oriented file (or your OS
               doesn't have record-oriented files), then you'll likely get a
               full chunk of data with every read. If a record is larger than
               the record size you've set, you'll get the record back in
               pieces. Trying to set the record size to zero or less will
               cause reading in the (rest of the) whole file.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl Script Integer Test

Working out a small problem, I have a need of a Perl snippet which might look something like this: use integer; ... if ($changingNumber / 2) { do something; } else { do something else; } ... What I want to happen is for "if" to resolve as "true" every time a whole... (3 Replies)
Discussion started by: LinQ
3 Replies

2. Shell Programming and Scripting

Perl inserting random negative integer

Hi All, i have problem here whenever i run this perl script that is pasted here, it inserts a negative number in place of PO_nbr . What the script does is reads a pipe delimited file and then using some values on the file it will query db to get few other values and then it inserts the... (4 Replies)
Discussion started by: selvankj
4 Replies

3. Shell Programming and Scripting

Adding a backslash in front of square brackets with sed

I'm trying to convert this line: to \ with sed. This is what I have so far: sed -e 's/\]*\)\]/\\\\\/' but this still gives me . Any suggestions? (15 Replies)
Discussion started by: lehaste
15 Replies

4. Shell Programming and Scripting

md5sum on a file with backslash in its name

Hi there, I found something very weird! Should I report that as a bug or is it me misusing the command? I've got a file with a backslash in its name. I know it's a horrible policy but it's not me. The file came from a mac computer because this is a backup server. Anyway, when using... (8 Replies)
Discussion started by: chebarbudo
8 Replies

5. Shell Programming and Scripting

how to compare string integer with an integer?

hi, how to I do this? i="4.000" if ; then echo "smaller" fi how do I convert the "4.000" to 4? Thanks! (4 Replies)
Discussion started by: h0ujun
4 Replies

6. Shell Programming and Scripting

Echo backslash

If I echo "\\" I get a backslash returned ~$ echo "\\" \ Why doesn't this work: string=`echo "\\"` echo $string I get the error message: bash: command substitution: line 1: unexpected EOF while looking for matching `"' bash: command substitution: line 2: syntax error: unexpected end... (2 Replies)
Discussion started by: locoroco
2 Replies

7. Shell Programming and Scripting

perl string matching problem (two backslash)

I have a few .tex files generated with html2latex. They have some extra \\ that generate error with pdflatex, so I would like to get rid of them. This perl -p -i -e s/\\\\//g myfile.tex with or without simple or double quote remove all of the backslashes, also the single ones needed by tex. How... (2 Replies)
Discussion started by: ahsog
2 Replies

8. Shell Programming and Scripting

bash - add backslash in front of variables w/ spaces

Hello, Im writing a script that works by recursively going into directories with find. But I have some directories that have spaces in them.. so I need to parse the variables to add a backslash before the spaces. Im not exactly sure how how to do this in bash, and honestly I dont think I know... (3 Replies)
Discussion started by: trey85stang
3 Replies

9. UNIX for Dummies Questions & Answers

Escaping backslash

I have a variable containt something like this, c:\mask\mask. How can I escape "\" in the values? I want the value as it it. (9 Replies)
Discussion started by: swmk
9 Replies

10. UNIX for Dummies Questions & Answers

backslash issues

Hi, I have a script which looks through an input file and takes data from the file to use within the script. Everything works fine until the script reads the item \windows\directory\structure\ from the input file into a variable. As unix sees the backslash as an escape character, the... (5 Replies)
Discussion started by: Bab00shka
5 Replies
Login or Register to Ask a Question