logo
down
shadow

Perl Get the web content then writing it as a text file


Perl Get the web content then writing it as a text file

By : Tilia
Date : November 17 2020, 11:55 AM
Hope this helps The first argument to open is the filehandle name, not the actual name of the file. That comes later in the open function.
Change your code to:
code :
my $FOutput = get "http://website/Logs/Log_number.ini"; # your content should be stored in this 
                                                        # variable, you need to write data to your output file.
my $FInput = "/home/User/Downloads/text";
open OUTPUT_FILEHANDLE, '>', $FInput or die "could not open $FInput: $!"; # give a name to the file 
                                                                          # handle, then supply the file name itself after the mode specifier. 
                                                                          # You want to WRITE data to this file, open it with '>'
my $ctr;
my @results;
my @words = split(/(\r|\n)/, $FOutput); # create an array of words from the content from the logfile
                                        # I'm not 100% sure this will work, but the intent is to show
                                        # an array of 'lines' corresponding to the data

# here, you want to print the results of your grep to the output file
@results = grep /RoomOutProcessTT/, @words;
print OUTPUT_FILEHANDLE "@results\n"; # print to your output file
# close the output file here, since you re-open it in the next few lines.
close OUTPUT_FILEHANDLE;

# not sure why you're re-opening the file here... but that's up to your design I suppose
open INPUT_FILEHANDLE, '<', $FInput or die "could not open $FInput: $!"; # open it for read
while(<INPUT_FILEHANDLE>){
    $ctr = grep /RoomOutProcessTT/, split ' ' , $_;             
    $ctr += $ctr; 
}   
print "RoomOutProcessTT Count: $ctr\n"; # print to stdout
close INPUT_FILEHANDLE;  # close your file handle


Share : facebook icon twitter icon
Perl - Format text data before writing to a file

Perl - Format text data before writing to a file


By : Don Han
Date : March 29 2020, 07:55 AM
it should still fix some issue I am writing data in a file. The file will look like this.
code :
$str .= sprintf("[%-30s] [%-30s] [%-30s]\n",
    $section1_data,
    $section2_data,
    $section3_data,
);
Perl - Writing Network content as a text file

Perl - Writing Network content as a text file


By : paluri anooj
Date : March 29 2020, 07:55 AM
help you fix your problem Pipe the values through the chr function to get the text:
code :
use strict;
use warnings;

my @str = (77, 97, 121, 32, 32, 49);

print map {chr $_} @str;
May  1
reading text file and writing to two dimensional array in perl?

reading text file and writing to two dimensional array in perl?


By : Pierre Örnryd
Date : March 29 2020, 07:55 AM
will help you I read your question as How do I populate the hashes %grade1 and %grade2 from the files data1.txt and data2.txt?
I also assume that your files data1.txt and data2.txt have the following structure (whitespace separated):
code :
marry 10 65 23
john 20 30 40
sub read_grades_from_file
{
    my $filename = shift;
    my $result   = {};

    open( my $fh, '<:encoding(UTF-8)', $filename )
      or die "Could not open file '$filename' $!\n";
    while ( my $row = <$fh> ) {
        next unless $row =~ /\S/;    # skip empty lines
        my ( $name, $quiz1, $quiz2, $quiz3 ) = split( ' ', $row );
        $result->{$name} = {
            quiz1 => $quiz1,
            quiz2 => $quiz2,
            quiz3 => $quiz3,
        };
    }
    close($fh);
    return $result;
}
my $result = read_grades_from_file('data1.txt');    # returns hashref
my %grade1 = %{$result};                            # dereference $result to make it a hash

$result = read_grades_from_file('data2.txt');
my %grade2 = %{$result};
Inverting content of a first given text file and writing the inverted content to a second text file

Inverting content of a first given text file and writing the inverted content to a second text file


By : user3554226
Date : March 29 2020, 07:55 AM
it should still fix some issue I don't want to give you the full answer because this seems like homework but this should be enough to get you started, the code is commented.
code :
Days = dict()
Days['Monday'] = 'First Day of the Week'
Days['Tuesday'] = 'Second Day of the Week'
Days['Wednesday'] = 'Third Day of the Week'
Days['Thursday'] = 'Fourth Day of the Week'
Days['Friday'] = 'Fith Day of the Week'
Days['Saturday'] = 'Sixth Day of the Week'
Days['Sunday'] = 'Seventh Day of the Week'

def invert(dic):
    a = list(dic.items()) # Casts dict to list
    a.reverse() # reverses lsit
    return dict(a) # cast back to dictionary and return

with open("Output.txt", 'w') as f: # Opens a file for WRITING "Output.txt" in CURRENT working directory
                                   # Creates a new file if it does not exist or truncates the file if it exists
   for i in invert(Days).items():   # loop through keys and values      
       f.write(f"{i}\n")    # writes the items and adds a new line
('Sunday', 'Seventh Day of the Week')
('Saturday', 'Sixth Day of the Week')
('Friday', 'Fith Day of the Week')
('Thursday', 'Fourth Day of the Week')
('Wednesday', 'Third Day of the Week')
('Tuesday', 'Second Day of the Week')
('Monday', 'First Day of the Week')
Writing results in a text file with perl

Writing results in a text file with perl


By : prashant jha
Date : March 29 2020, 07:55 AM
around this issue print $outFile $fh is printing the value of the file handle $fh to the file handle $outFile. Instead you want to print the entire current line, which is in $_.
There are a couple of other improvements that can be made
Related Posts Related Posts :
  • Content-Type setting for .MTS files
  • Seek function not working in perl
  • Perl syntax error printing list index
  • perl matching syntax with mail filter
  • Error Handling Using Perl Tkx
  • Perl : calculation of time in format hh:mm:ss,sss
  • Remove element from array containing empty or whitespace character in Perl
  • Running an external command in Perl / Tkx without blocking the GUI (Windows)
  • Passing multiple values to a Perl program in a single command line argument
  • perl Parallel::ForkManager stuck in this script?
  • Unable to escape @ sign in perl
  • Loop to define buttons in Perl / Tkx
  • Why can't the Opsview_rest Perl script not find the OPSVIEW_URL_PREFIX Environment variable using $ENV{var} while it has
  • Get http-response header with Perl's File::Fetch
  • perl $CGI::POST_MAX all parameters
  • Perl Foreach until loop
  • login failed to remote host - prompt does not match at /usr/lib/perl5/site_perl/5.10.0/Net/Appliance/Session/Transport.p
  • How is a literal list having one element represented unambiguously in perl?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org