Perl Read Pdf File

Active3 years, 7 months ago

I have a simple Perl script to read a file line by line. Code is below. I want to display two lines and break the loop. But it doesn't work. Where is the bug?

ЯegDwight

Reading and processing text files is one of the common tasks done by Perl. For example, often you encounter a CSV file (where CSV stand for Comma-separated values) and you need to extract some information from there. Here is an example with three solutions. Good, Better, Best. Errors reading PDF with CAM-PDF: use of uninitialized value in addition line 667 Hot Network Questions What does a Nintendo Game Boy do when turned on without a game cartridge inserted? The above way of handling files is used in Perl scripts when you absolutely have to have the file opened or there is no point in running your code. For example when the whole job of your script is to parse that file.

22.1k9 gold badges38 silver badges50 bronze badges
user534009Readuser534009
6354 gold badges17 silver badges25 bronze badges

5 Answers

Perl Read Line From File

If you had use strict turned on, you would have found out that $++foo doesn't make any sense.

Here's how to do it:

This takes advantage of the special variable $. which keeps track of the line number in the current file. (See perlvar)

If you want to use a counter instead, use

friedofriedo
49k15 gold badges108 silver badges175 bronze badges

With these types of complex programs, it's better to let Perl generate the Perl code for you:

Which will gladly tell you the answer,

Pdf

Alternatively, you can simply run it as such from the command line,

Greg Bacon
107k27 gold badges172 silver badges226 bronze badges
Evan CarrollEvan Carroll
39.4k26 gold badges156 silver badges269 bronze badges

you need to use ++$counter, not$++counter, hence the reason it isn't working..

NoobEditor
11.7k10 gold badges55 silver badges89 bronze badges
DoonDoon
16.8k1 gold badge33 silver badges41 bronze badges

In bash foo is the name of the variable, and $ is an operator which means 'get the value of'.

Perl Read Pdf File

In perl $foo is the name of the variable.

jwgjwg

Pdf Reader

3,7412 gold badges29 silver badges54 bronze badges
Evan Carroll

Perl Read Pdf File

39.4k26 gold badges156 silver badges269 bronze badges
tchristtchrist
70.7k25 gold badges111 silver badges163 bronze badges

Perl Read A File

Not the answer you're looking for? Browse other questions tagged perl or ask your own question.