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

hi
the following code i have copied whith some variation somewhere from this great forum are supposed to load a picture from some directory to webbrowser on AxWindow
# Hosting WebBrowser # use Cwd; use Win32::GUI; use Win32::OLE; use Win32::GUI::AxWindow; my $desk = Win32::GUI::GetDesktopWindow(); my $dw = Win32::GUI::Width($desk); my $dh = Win32::GUI::Height($desk); my $dir = getcwd; # main Window $Window = new Win32::GUI::Window ( -title => "Win32::GUI::AxWindow and Win32::OLE", -pos => [0, 0], -size => [$dw, $dh], -name => "Window", ) or die "new Window"; # Create AxWindow $Control = new Win32::GUI::AxWindow ( -parent => $Window, -name => "Control", -pos => [0, 0], -size => [$dw, $dh], -control => "Shell.Explorer.2", ) or die "new Control"; #my $filejpg = $dir . '/' . 'pic.jpg'; # Get Ole object $OLEControl = $Control->GetOLE(); $OLEControl->Navigate("about:Blank"); # Clear control $OLEControl->{Document}->write('<html><body><img src = "c:/test/pic.jp +g" /></body></html>'); # Write Html # Event loop $Window->Show(); Win32::GUI::Dialog(); # Main window event handler sub Window_Terminate { # Release all before destroy window undef $OLEControl; $Control->Release(); return -1; } sub Window_Resize { if (defined $Window) { ($width, $height) = ($Window->GetClientRect)[2..3]; $Control->Resize ($width, $height); } }
but i want to replace the true directory "c:/test/pic.jpg" with a variable such as:
my $file = "c:/test/pic.jpg";
so i can replace the corresponding line above with
$OLEControl->{Document}->write('<html><body><img src = "$file" /></bod +y></html>'); # Write Html
it does not work for me using a variable while it is working using a "c:/test/pic.jpg" , what is the solution. i am using activestate perl 5.10 windows xp
regards

Replies are listed 'Best First'.
Re: can't replace a directory with a variable
by psini (Deacon) on Jul 01, 2008 at 14:35 UTC

    Try this:

    $OLEControl->{Document}->write("<html><body><img src = '$file' /></body></html>"); # Write Html

    Using double quotes " instead of single ones ' you tell perl to interpolate the variable reference inside the string.

    Or, better, use sprintf:

    $OLEControl->{Document}->write(sprintf('<html><body><img src = "%s" /></body></html>',$file)); # Write Html

    that gives you more control on how the string is built.

    Rule One: "Do not act incautiously when confronting a little bald wrinkly smiling man."

Re: can't replace a directory with a variable
by NetWallah (Canon) on Jul 01, 2008 at 14:39 UTC
    Interchange your single and double quotes (Single quotes do not Intrapolate!). Alternatively, you can use the qq() function.
    $OLEControl->{Document}->write("<html><body><img src = '$file' /></bod +y></html>"); #

         Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

Re: can't replace a directory with a variable
by rovf (Priest) on Jul 02, 2008 at 07:09 UTC

    If you insist in your HTML attributes being delimeted by double quotes, use

    $OLEControl->{Document}->write(qq(<html><body><img src = "$file" /></b +ody></html>));

    -- 
    Ronald Fischer <ynnor@mm.st>