spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories

Perl file I/O issues: Script erasing all file contents instead of just removing numbers.


  • You used @array = <in>; instead of @array = <$in>;!
  • When you actually tried to read the file using while (<$in>), it had already been clobbered by open '>'.
  • s/d/ / doesn't just remove a digit; it adds a newline in its place.

#!/usr/bin/perl

use strict;
use warnings;

my $qfn = 'rmv_num_lines.txt';

open my $in_fh, '<', $qfn
   or die "Can't open $qfn: $!
";

my @lines = <$in_fh>;

open my $out_fh, '>', $qfn
   or die "Can't create $qfn: $!
";

for my $line (@lines) {
    $line =~ s/^d+ //;
    print $out_fh $line;
}

As a one-liner:

perl -i -pe's/^d+ //' rmv_num_lines.txt

Categories : Perl

Related to : Perl file I/O issues: Script erasing all file contents instead of just removing numbers.
Android RecyclerView Removing Item - 2 Animation Issues
That does not make sense. If you remove item at 0 (assuming it is visible and top item), there would be a "remove" for that item and "move" animation for all other visible views + one more (the new item to fill the new space but it comes with a move animation from below the list). Can you post some code?

Categories : Android
Removing extended ASCII characters. Linux script (128-255)
The nn syntax is octal (where n is 0-7), so: 128 = invalid octal 200 = 128 255 = 173 377 = 255 So you want: 200-377

Categories : Linux
C++ Erasing element from a vector of pointers
You're deleting the account from a copy: std::vector<T*> getDatabase () const; std::vector<Account*> db = m_acctDb.getDatabase(); You need to delete from the actual database, so you want the usage to be: std::vector<T*>& getDatabase (); const std::vector<T*>& getDatabase () const; std::vector<Account*>& db = m_acctDb.getDatabase();

Categories : C++
How can I animate/slide a div into view while moving the contents as opposed to just revealing the contents?
If you want to use jQuery animate check this fiddle: http://jsfiddle.net/cgLy77us/1/ Script: $(document).ready(function(){ var SlideUpAnimate = function(duration, callback){ var $element = $("#slideUp"); var startPosition = $(window).scrollTop() + $(window).height() + $element.height(); var finishPosition = $element.position().top; $element.css("top", startPosition + "px").show(

Categories : Javascript
How can convert file with contents of string to the file with contents of byte?
You are essentially copying the contents of a file...You're getting what you would normally get if you copy/pasted the file (Each ASCII character is a byte) If your aim is to compact the file, right now your file is a tightly packed as it can be, without an actual compression algorithm being run on it.

Categories : Java
Recently Add
SSL error calling Perl web service via https using LWP
SOAP::Lite always faults in debug mode
perl referencing a hash outside of the scope that populated it (histogram)
Perl script to print out all the lines containing a keyword and the line below it
PERL Unicode Escape string pass from command line argument wrong output
Perl process crashes after handling signal
Marpa: Can I explicitly disallow keywords as identifiers?
Perl: Import text, containing ÅÄÖ, from file
error using perl - Proc::ProcessTable. works in cmd line, not in .pl file
DBIx::Class chaining resultsets with same table in prefetch
Time as input, print timetable in Perl
compare values of different tables perl
Automatically increasing ID generation using PERL
Syntax Error, first line after dostuff
Delete files in a folder using Perl
Perl '-d' operator is not detecting a directory
Perl appending text to new line
write_timeout in IO::Socket::Timeout
Using ForkManager and Perl properly?
Is a cyclic dependency solved with require?
Posting metric to google analytics from perl script
How can I check if a user enters my page the first time?
Sorting arrays of intervals in perl?
Perl: How to get the link target of a soundcloud feed mp3
Uninitialized value in concatenation
Perl code - pipe "|" in `open()` statement
perl command line backticks with matrix
Perl OO - Creating a list of objects
extract gene-id + function annotation from .gff
How to receive parameters and values from POST method in Perl CGI?
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.