I'd like to know what the error means, but the real question is how to transform an array into a hash. ... %data = @info =~ /(\w+)\s*(\w+)/g; # Line that gives error ... Applying pattern match to @array will act on scalar(@array) at e.pl line 29
You can get more information on any error by putting "use diagnostics;" in your script (or looking up the error via perldoc perldiag or the splain utility).
$ echo 'Applying pattern match to @array will act on scalar(@array) at
+ e.pl lin
e 29'|splain|fmt
Applying pattern match to @array will act on scalar(@array) at e.pl li
+ne
29 (#1)
(W misc) The pattern match (//), substitution (s///),
and transliteration (tr///) operators work on scalar values.
If you apply one of them to an array or a hash, it will convert th
+e
array or hash to a scalar value -- the length of an array, or the
population info of a hash -- and then work on that scalar value.
This is probably not what you meant to do. See perlfunc/grep and
perlfunc/map for alternatives.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|