petetbp has asked for the wisdom of the Perl Monks concerning the following question:

I am new to both Perl and Intershop. I am trying to automate the process of updating the stock levels on an Intershop 4 web site. The simplest way I have found to perform this task is for Perl to simulate a human user interacting with the web site.

I am having trouble uploading the stock level file. I am creating the file directly in the request. I include the error and part of the code below. Can anyone help?

“Can't open file ARRAY(0x2102554): No such file or directory at E:/Perl/site/lib/HTTP/Request/Form. line 339”

$response = $ua->request(GET "$IS_URL/$session_id/Service/SysAdmin/Dat +aImport/1/2"); my $tree = HTML::TreeBuilder->new; $tree->parse($response->content); $tree->eof(); my @forms = $tree->find_by_tag_name('FORM'); die "What, no forms" unless @forms; my $f = HTTP::Request::Form->new($forms[0], "$IS_URL/$session_id/Servi +ce/SysAdmin/DataImport/1/2"); $f->field("BUTTON", "Upload"); $f->field("DescriptionFile", "StockLevelImport.cfg"); $f->field("DataFile", [undef, "stock_level", $file]); my $response = $ua->request($f->press()); print $response->content if $response->is_success;

Replies are listed 'Best First'.
Re: Can't open file ARRAY
by antifun (Sexton) on Oct 15, 2002 at 14:22 UTC

    This line

    my @forms = $tree->find_by_tag_name('FORM');

    is probably returning an arrayref, not an array. So when you do this, @forms is actually a 1-element array where the first element is a reference to what you actually want.

    If this is the problem, just use a reference and dereference the array appropriately. To wit:

    my $forms = $tree->find_by_tag_name('FORM'); die "What, no forms" unless scalar @{$forms}; my $f = HTTP::Request::Form->new($$forms[0], "$IS_URL/$session_id/Serv +ice/SysAdmin/DataImport/1/2");

    (Forgot to mention: you can see if the function returns an arrayref by looking at ref ($tree->find_by_tag_name('FORM')) -- if it's ARRAY then there's your answer :))

    (Addendum: I'm totally wrong about what's going on here. I think you really have a problem with your use of H::R::F::field. Specifically that you can't set DataFile to an arrayref. At least, I don't think you can. That's what I get for not checking the POD...)


    ---
    "I hate it when I think myself into a corner."
    Matt Mitchell
Re: Can't open file ARRAY
by Abigail-II (Bishop) on Oct 15, 2002 at 14:24 UTC
    Your code fragment doesn't contain a call to open, nor does it contain a die() capable of generating the stated error message. However, it looks like you are using a reference to an array instead of a file as argument to open. But this is guessing, as all we see the output of some unknown die() call, and not the context.

    Abigail

Re: Can't open file ARRAY
by Joost (Canon) on Oct 15, 2002 at 14:25 UTC
    I'm guessing a bit here; if I need to upload stuff I generally use LWP directly, but reading tru the docs for H:R:F i could not find an explanation for this:

    $f->field("DataFile", [undef, "stock_level", $file]);
    Is this correct? Should you not be something like:

    $f->field("DataFile", $file);

    If this isn't the problem you might figure out which line is causing the problem by commenting out a few...

    HTH.

    -- Joost downtime n. The period during which a system is error-free and immune from user input.