Thank you for the pointer to use File::Temp module. Able to generate a temporary file name but not sure how to write the content from a string into the temp file, simple assignment does not work viz., $tempFile = $stringValue; Following is my code, please advice:
use strict; use File::Find; use MIME::Base64; use File::Temp qw(tempfile); sub loadFiles(); #udf sub mySub(); #udf my @files = (); my $dir = shift || die "Argument missing: directory name\n"; my $finalLoc; my $filePath; my $fileContents; my $base64EncFile; my $domain = "ABC"; my $devFilePath; my $deviceDir; my $position; my $user = "admin"; my $encPwd = "kaosapdkasd="; my $decPwd; my $response; my $temp; my $tempFilename; loadFiles(); #call #map ({ print "$_\n"; } @files); foreach (@files) { $filePath = $_; $filePath =~ s/\//\\/g; $devFilePath = $_; $devFilePath =~ s/\\/\//g; $position = index( $devFilePath, "RPDM" ); $deviceDir = "local:///" . substr( $devFilePath, $position ); open( FILE, "< $filePath" ); $fileContents = do { local $/; <FILE> }; $base64EncFile = encode_base64($fileContents); $base64EncFile =~ s/[\x0A\x0D]//g; #creating a temp file to be able to set large files (~500 kb) $temp = File::Temp->new( TEMPLATE => "tempXXXXXXXXX", UNLINK => 0 ) or die "Could not make tempfile: $!"; close $temp or die "Could not close tempfile: $!"; $tempFilename = $temp->filename; print "$filePath\n"; print "$tempFilename \n"; my $dpString = "<env:Envelope xmlns:env='http://schemas.xmlsoap.org/soap/envelope/' x +mlns:dp='http://www.datapower.com/schemas/management'><env:Body><dp:r +equest domain='$domain'><dp:set-file name='$deviceDir'>" . $base64EncFile . "</dp:set-file></dp:request></env:Body></env:Envelope>"; $decPwd = decode_base64($encPwd); #***HOW TO GET THE CONTENTS FROM $dpString INTO $tempFilename OTHER TH +AN SIMPLE ASSIGNMENT ? $tempFilename = $dpString; #print "\n$dpString\n"; #$response = system('C:\\apps\\curl-7.15.0\\curl.exe', '-#', '-k', '-u +', "admin:$decPwd", '--data-binary', "$dpString", 'https://hostxyz:55 +50/service/mgmt/current'); # print "$response\n"; system( 'C:\\apps\\curl-7.15.0\\curl.exe', '-#', '-k', '-u', "admin:$decPwd", '--data-binary', "$dpString", 'https://hostxyz:5550/service/mgmt/current' ); close(FILE); print "\n--------------------------------------------------------- +--\n"; } sub loadFiles() { find( \&mySub, "$dir" ); #custom subroutine find, parse $dir } # following gets called recursively for each file in $dir, check $_ to + see if you want the file! sub mySub() { push @files, $File::Find::name if (/(\.xml|\.xsl|\.xslt|\.ffd|\.dpa|\.wsdl|\.xsd)$/i) ; # modify the regex as per your needs or pass it as another +arg }

In reply to Re^4: Using Windows Curl.exe in Perl by liv2luv
in thread Using Windows Curl.exe in Perl by liv2luv

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.