Is the argument you're passing to foo a hash ref? That is, is it what CSS::Style::selectors() expects?

CSS::Style::selectors probably expects to be called like a method (so something like CSS::Style->selectors(shift) instead). You might need to create a CSS::Style object first and then call the method selectors on that with the appropriate argument. Update: You probably shouldn't be using CSS::Style directly in the first place; it appears that all of this should be done via CSS.pm.

In any case, read the doc and verify that $_[0] (what shift gets the value from) really contains what you want.

Update2: Since you said you're new to Perl, here's probably what you want... I've tried to comment it well enough... read the doc and then ask if you need clarification... (Not tested, BTW, all from what the doc says.)

sub foo { my ($file, $selector_name) = @_; # Create CSS object use CSS; my $css = CSS->new; # Read CSS from file passed as first arg to foo $css->read_file($file); # Get CSS::Style object associated with the name of the # selector passed as the second arg to foo my $style = $css->get_style_by_selector($selector_name); # Get selectors (serialized) my $selectors = $style->selectors; # ... } # Example call (as I have foo, it returns nothing, you # can fill that in) my $ret = foo('styles.css', 'body');

In reply to Re: Can't use string ("STRING") as a HASH ref - Help! by The Mad Hatter
in thread Can't use string ("STRING") as a HASH ref - Help! by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.