Perl Reading from File

is there a perl equivalent to sscanf? or something where I get the strings separated by spaces?

To separate strings by spaces you can use split() with a space as a delimiter.

Or in a more general sense, some whitespace characters. A quick example:

[testcn@bernardchan testcn]$ perl -e '@ary = split(/\s+/, "This  is a space"); $, = "\n"; print @ary;'
This
is
a
space

Note that there are two space characters between 'This' and 'is', but treated as a single whitespace unit because the delimiter is any sequence of whitespace characters.

If you want something really like the C sscanf(), I found this module on CPAN:

I haven't used it before, so I have no idea whether it works. And first of all you need to know how to install it, as Perl does not ship this module with the distribution.

Trust me, regular expression is usually the "more proper" way to do string extraction in Perl. That's why perl has a printf() emulation but not a scanf() emulation in the basic function set. :smiley: