Results 1 to 4 of 4

Thread: conversion of code in perl and python

  1. #1
    Join Date
    Jul 2010
    Beans
    85

    conversion of code in perl and python

    How to convert below bash code in perl and python.


    Code:
      for BLOCK in /sys/block/emcpow* 
    
    do         
    echo "100000" > "$BLOCK"/queue/nr_requests         
    echo "noop" > "$BLOCK"/queue/scheduler 
    
    done

  2. #2
    Join Date
    Feb 2009
    Beans
    1,469

    Re: conversion of code in perl and python

    Perl (untested):
    Code:
    for (glob '/sys/block/emcpow*') {
        open REQ, '>', "$_/queue/nr_requests";
        print REQ "100000\n";
        close REQ;
    
        open SCHED, '>', "$/queue/scheduler";
        print SCHED "noop\n";
        close SCHED;
    }
    Don't know why you'd want to do that though; the bash version makes a lot more sense.
    Last edited by trent.josephsen; August 24th, 2012 at 12:26 AM. Reason: forgot newline

  3. #3
    Join Date
    Jul 2010
    Beans
    85

    Re: conversion of code in perl and python

    Below script not changing the values, it is not working correctly.

    Quote Originally Posted by trent.josephsen View Post
    Perl (untested):
    Code:
    for (glob '/sys/block/emcpow*') {
        open REQ, '>', "$_/queue/nr_requests";
        print REQ "100000\n";
        close REQ;
    
        open SCHED, '>', "$/queue/scheduler";
        print SCHED 'noop';
        close SCHED;
    }

  4. #4
    Join Date
    Feb 2009
    Beans
    1,469

    Re: conversion of code in perl and python

    I forgot to add a newline to "noop" (edited in my prior post).

    If that doesn't fix your problem, well, I don't know why. Do you understand how it works or did you just copy and paste it?

    Run it with perl -w at least to enable warnings.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •